Skip to content

asn1 incorrectly encoding integers #997

@nwaples

Description

@nwaples
Before filing a bug, please check whether it has been fixed since
the latest release: run "hg pull -u" and retry what you did to
reproduce the problem.  Thanks.

What steps will reproduce the problem?
1.

package main

import (
    "fmt"
    "asn1"
    "encoding/hex"
)

func main() {
    buf, _ := asn1.MarshalToMemory(-128)
    fmt.Println(hex.EncodeToString(buf))

    buf, _ = asn1.MarshalToMemory(128)
    fmt.Println(hex.EncodeToString(buf))

    var x int
    asn1.Unmarshal(&x, buf)
    fmt.Println(x)
}


What is the expected output?
020180
02020080
128

What do you see instead?
0200
020180
-128

What is your $GOOS?  $GOARCH?
linux 386

Which revision are you using?  (hg identify)
8c17e4da43c1+ tip

Please provide any additional information below.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions