mirror of
https://github.com/golang/go
synced 2024-11-22 04:04:40 -07:00
asn1: fix parsing of elements after a string in a structure.
Fixes #516. R=rsc CC=golang-dev, golang-dev https://golang.org/cl/184080
This commit is contained in:
parent
2f63eb243c
commit
72b97e46a3
@ -609,6 +609,7 @@ func parseField(v reflect.Value, bytes []byte, initOffset int, params fieldParam
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
innerBytes := bytes[offset : offset+t.length]
|
innerBytes := bytes[offset : offset+t.length]
|
||||||
|
offset += t.length
|
||||||
|
|
||||||
// We deal with the structures defined in this package first.
|
// We deal with the structures defined in this package first.
|
||||||
switch fieldType {
|
switch fieldType {
|
||||||
@ -619,13 +620,11 @@ func parseField(v reflect.Value, bytes []byte, initOffset int, params fieldParam
|
|||||||
if err1 == nil {
|
if err1 == nil {
|
||||||
reflect.ArrayCopy(sliceValue, reflect.NewValue(newSlice).(reflect.ArrayOrSliceValue))
|
reflect.ArrayCopy(sliceValue, reflect.NewValue(newSlice).(reflect.ArrayOrSliceValue))
|
||||||
}
|
}
|
||||||
offset += t.length
|
|
||||||
err = err1
|
err = err1
|
||||||
return
|
return
|
||||||
case bitStringType:
|
case bitStringType:
|
||||||
structValue := v.(*reflect.StructValue)
|
structValue := v.(*reflect.StructValue)
|
||||||
bs, err1 := parseBitString(innerBytes)
|
bs, err1 := parseBitString(innerBytes)
|
||||||
offset += t.length
|
|
||||||
if err1 == nil {
|
if err1 == nil {
|
||||||
structValue.Set(reflect.NewValue(bs).(*reflect.StructValue))
|
structValue.Set(reflect.NewValue(bs).(*reflect.StructValue))
|
||||||
}
|
}
|
||||||
@ -634,7 +633,6 @@ func parseField(v reflect.Value, bytes []byte, initOffset int, params fieldParam
|
|||||||
case timeType:
|
case timeType:
|
||||||
ptrValue := v.(*reflect.PtrValue)
|
ptrValue := v.(*reflect.PtrValue)
|
||||||
time, err1 := parseUTCTime(innerBytes)
|
time, err1 := parseUTCTime(innerBytes)
|
||||||
offset += t.length
|
|
||||||
if err1 == nil {
|
if err1 == nil {
|
||||||
ptrValue.Set(reflect.NewValue(time).(*reflect.PtrValue))
|
ptrValue.Set(reflect.NewValue(time).(*reflect.PtrValue))
|
||||||
}
|
}
|
||||||
@ -644,7 +642,6 @@ func parseField(v reflect.Value, bytes []byte, initOffset int, params fieldParam
|
|||||||
switch val := v.(type) {
|
switch val := v.(type) {
|
||||||
case *reflect.BoolValue:
|
case *reflect.BoolValue:
|
||||||
parsedBool, err1 := parseBool(innerBytes)
|
parsedBool, err1 := parseBool(innerBytes)
|
||||||
offset += t.length
|
|
||||||
if err1 == nil {
|
if err1 == nil {
|
||||||
val.Set(parsedBool)
|
val.Set(parsedBool)
|
||||||
}
|
}
|
||||||
@ -652,7 +649,6 @@ func parseField(v reflect.Value, bytes []byte, initOffset int, params fieldParam
|
|||||||
return
|
return
|
||||||
case *reflect.IntValue:
|
case *reflect.IntValue:
|
||||||
parsedInt, err1 := parseInt(innerBytes)
|
parsedInt, err1 := parseInt(innerBytes)
|
||||||
offset += t.length
|
|
||||||
if err1 == nil {
|
if err1 == nil {
|
||||||
val.Set(parsedInt)
|
val.Set(parsedInt)
|
||||||
}
|
}
|
||||||
@ -660,7 +656,6 @@ func parseField(v reflect.Value, bytes []byte, initOffset int, params fieldParam
|
|||||||
return
|
return
|
||||||
case *reflect.Int64Value:
|
case *reflect.Int64Value:
|
||||||
parsedInt, err1 := parseInt64(innerBytes)
|
parsedInt, err1 := parseInt64(innerBytes)
|
||||||
offset += t.length
|
|
||||||
if err1 == nil {
|
if err1 == nil {
|
||||||
val.Set(parsedInt)
|
val.Set(parsedInt)
|
||||||
}
|
}
|
||||||
@ -671,7 +666,7 @@ func parseField(v reflect.Value, bytes []byte, initOffset int, params fieldParam
|
|||||||
|
|
||||||
if structType.NumField() > 0 &&
|
if structType.NumField() > 0 &&
|
||||||
structType.Field(0).Type == rawContentsType {
|
structType.Field(0).Type == rawContentsType {
|
||||||
bytes := bytes[initOffset : offset+t.length]
|
bytes := bytes[initOffset:offset]
|
||||||
val.Field(0).SetValue(reflect.NewValue(RawContent(bytes)))
|
val.Field(0).SetValue(reflect.NewValue(RawContent(bytes)))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -686,7 +681,6 @@ func parseField(v reflect.Value, bytes []byte, initOffset int, params fieldParam
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
offset += t.length
|
|
||||||
// We allow extra bytes at the end of the SEQUENCE because
|
// We allow extra bytes at the end of the SEQUENCE because
|
||||||
// adding elements to the end has been used in X.509 as the
|
// adding elements to the end has been used in X.509 as the
|
||||||
// version numbers have increased.
|
// version numbers have increased.
|
||||||
@ -699,7 +693,6 @@ func parseField(v reflect.Value, bytes []byte, initOffset int, params fieldParam
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
newSlice, err1 := parseSequenceOf(innerBytes, sliceType, sliceType.Elem())
|
newSlice, err1 := parseSequenceOf(innerBytes, sliceType, sliceType.Elem())
|
||||||
offset += t.length
|
|
||||||
if err1 == nil {
|
if err1 == nil {
|
||||||
val.Set(newSlice)
|
val.Set(newSlice)
|
||||||
}
|
}
|
||||||
|
@ -263,6 +263,11 @@ type TestContextSpecificTags2 struct {
|
|||||||
B int
|
B int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type TestElementsAfterString struct {
|
||||||
|
S string
|
||||||
|
A, B int
|
||||||
|
}
|
||||||
|
|
||||||
var unmarshalTestData []unmarshalTest = []unmarshalTest{
|
var unmarshalTestData []unmarshalTest = []unmarshalTest{
|
||||||
unmarshalTest{[]byte{0x02, 0x01, 0x42}, newInt(0x42)},
|
unmarshalTest{[]byte{0x02, 0x01, 0x42}, newInt(0x42)},
|
||||||
unmarshalTest{[]byte{0x30, 0x08, 0x06, 0x06, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d}, &TestObjectIdentifierStruct{[]int{1, 2, 840, 113549}}},
|
unmarshalTest{[]byte{0x30, 0x08, 0x06, 0x06, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d}, &TestObjectIdentifierStruct{[]int{1, 2, 840, 113549}}},
|
||||||
@ -277,6 +282,7 @@ var unmarshalTestData []unmarshalTest = []unmarshalTest{
|
|||||||
unmarshalTest{[]byte{0x30, 0x08, 0xa1, 0x03, 0x02, 0x01, 0x01, 0x02, 0x01, 0x02}, &TestContextSpecificTags2{1, 2}},
|
unmarshalTest{[]byte{0x30, 0x08, 0xa1, 0x03, 0x02, 0x01, 0x01, 0x02, 0x01, 0x02}, &TestContextSpecificTags2{1, 2}},
|
||||||
unmarshalTest{[]byte{0x01, 0x01, 0x00}, newBool(false)},
|
unmarshalTest{[]byte{0x01, 0x01, 0x00}, newBool(false)},
|
||||||
unmarshalTest{[]byte{0x01, 0x01, 0x01}, newBool(true)},
|
unmarshalTest{[]byte{0x01, 0x01, 0x01}, newBool(true)},
|
||||||
|
unmarshalTest{[]byte{0x30, 0x0b, 0x13, 0x03, 0x66, 0x6f, 0x6f, 0x02, 0x01, 0x22, 0x02, 0x01, 0x33}, &TestElementsAfterString{"foo", 0x22, 0x33}},
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUnmarshal(t *testing.T) {
|
func TestUnmarshal(t *testing.T) {
|
||||||
|
Loading…
Reference in New Issue
Block a user