return
}
innerBytes := bytes[offset : offset+t.length]
+ offset += t.length
// We deal with the structures defined in this package first.
switch fieldType {
if err1 == nil {
reflect.ArrayCopy(sliceValue, reflect.NewValue(newSlice).(reflect.ArrayOrSliceValue))
}
- offset += t.length
err = err1
return
case bitStringType:
structValue := v.(*reflect.StructValue)
bs, err1 := parseBitString(innerBytes)
- offset += t.length
if err1 == nil {
structValue.Set(reflect.NewValue(bs).(*reflect.StructValue))
}
case timeType:
ptrValue := v.(*reflect.PtrValue)
time, err1 := parseUTCTime(innerBytes)
- offset += t.length
if err1 == nil {
ptrValue.Set(reflect.NewValue(time).(*reflect.PtrValue))
}
switch val := v.(type) {
case *reflect.BoolValue:
parsedBool, err1 := parseBool(innerBytes)
- offset += t.length
if err1 == nil {
val.Set(parsedBool)
}
return
case *reflect.IntValue:
parsedInt, err1 := parseInt(innerBytes)
- offset += t.length
if err1 == nil {
val.Set(parsedInt)
}
return
case *reflect.Int64Value:
parsedInt, err1 := parseInt64(innerBytes)
- offset += t.length
if err1 == nil {
val.Set(parsedInt)
}
if structType.NumField() > 0 &&
structType.Field(0).Type == rawContentsType {
- bytes := bytes[initOffset : offset+t.length]
+ bytes := bytes[initOffset:offset]
val.Field(0).SetValue(reflect.NewValue(RawContent(bytes)))
}
return
}
}
- offset += t.length
// We allow extra bytes at the end of the SEQUENCE because
// adding elements to the end has been used in X.509 as the
// version numbers have increased.
return
}
newSlice, err1 := parseSequenceOf(innerBytes, sliceType, sliceType.Elem())
- offset += t.length
if err1 == nil {
val.Set(newSlice)
}
B int
}
+type TestElementsAfterString struct {
+ S string
+ A, B int
+}
+
var unmarshalTestData []unmarshalTest = []unmarshalTest{
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, 0xa1, 0x03, 0x02, 0x01, 0x01, 0x02, 0x01, 0x02}, &TestContextSpecificTags2{1, 2}},
unmarshalTest{[]byte{0x01, 0x01, 0x00}, newBool(false)},
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) {