From 56b246dd4532be2dab47599027180e057b317521 Mon Sep 17 00:00:00 2001 From: Tom Dohrmann Date: Tue, 1 Oct 2024 08:37:21 +0200 Subject: [PATCH] encoding/asn1: unmarshal enumerated values correctly into ANY Previously we didn't unmarshal enumerated values into any, now we do. Also add a test-case that covers this. --- src/encoding/asn1/asn1.go | 4 ++++ src/encoding/asn1/asn1_test.go | 1 + 2 files changed, 5 insertions(+) diff --git a/src/encoding/asn1/asn1.go b/src/encoding/asn1/asn1.go index 56e007d3a65..f336c60cb5e 100644 --- a/src/encoding/asn1/asn1.go +++ b/src/encoding/asn1/asn1.go @@ -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. } diff --git a/src/encoding/asn1/asn1_test.go b/src/encoding/asn1/asn1_test.go index 9a605e245c1..ee2c55462bf 100644 --- a/src/encoding/asn1/asn1_test.go +++ b/src/encoding/asn1/asn1_test.go @@ -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) {