Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

encoding/asn1: unmarshal enumerated values correctly into ANY #69727

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/encoding/asn1/asn1.go
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,10 @@ func parseField(v reflect.Value, bytes []byte, initOffset int, params fieldParam
result = innerBytes
case TagBMPString:
result, err = parseBMPString(innerBytes)
case TagEnum:
parsedInt, err1 := parseInt32(innerBytes)
result = Enumerated(parsedInt)
err = err1
default:
// If we don't know how to handle the type, we just leave Value as nil.
}
Expand Down
1 change: 1 addition & 0 deletions src/encoding/asn1/asn1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,7 @@ var unmarshalTestData = []struct {
{[]byte{0x30, 0x05, 0x02, 0x03, 0x12, 0x34, 0x56}, &TestBigInt{big.NewInt(0x123456)}},
{[]byte{0x30, 0x0b, 0x31, 0x09, 0x02, 0x01, 0x01, 0x02, 0x01, 0x02, 0x02, 0x01, 0x03}, &TestSet{Ints: []int{1, 2, 3}}},
{[]byte{0x12, 0x0b, '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ' '}, newString("0123456789 ")},
{[]byte{0x30, 0x0f, 0x06, 0x0a, 0x2a, 0x86, 0x48, 0x86, 0xf8, 0x4d, 0x01, 0x0d, 0x01, 0x05, 0x0a, 0x01, 0x01}, &AttributeTypeAndValue{Type: ObjectIdentifier{1, 2, 840, 113741, 1, 13, 1, 5}, Value: Enumerated(1)}},
}

func TestUnmarshal(t *testing.T) {
Expand Down