Fix package tests.

This commit is contained in:
InfiniteLoopSpace 2018-11-14 13:24:33 +01:00
parent 8a079b0f10
commit f57379a647
3 changed files with 9 additions and 5 deletions

View File

@ -559,6 +559,10 @@ func parseTagAndLength(bytes []byte, initOffset int) (ret tagAndLength, offset i
}
return
}
if len(bytes) <= reoffset+reTag.length {
err = asn1.StructuralError{"indefinete lenght: length too large"}
return
}
reTag, reoffset, _ = parseTagAndLength(bytes, reoffset+reTag.length)
}
log.Println("indefinite length found (not DER)")
@ -928,7 +932,7 @@ func parseField(v reflect.Value, bytes []byte, initOffset int, params fieldParam
for i := 0; i < structType.NumField(); i++ {
if structType.Field(i).PkgPath != "" {
err = asn1.StructuralError{"struct contains unexported fields"}
err = asn1.StructuralError{Msg: "struct contains unexported fields"}
return
}
}

View File

@ -179,7 +179,7 @@ func TestBitString(t *testing.T) {
}
func TestBitStringAt(t *testing.T) {
bs := asn1.BitString{[]byte{0x82, 0x40}, 16}
bs := asn1.BitString{Bytes: []byte{0x82, 0x40}, BitLength: 16}
if bs.At(0) != 1 {
t.Error("#1: Failed")
}
@ -217,7 +217,7 @@ var bitStringRightAlignTests = []bitStringRightAlignTest{
func TestBitStringRightAlign(t *testing.T) {
for i, test := range bitStringRightAlignTests {
bs := asn1.BitString{test.in, test.inlen}
bs := asn1.BitString{Bytes: test.in, BitLength: test.inlen}
out := bs.RightAlign()
if !bytes.Equal(out, test.out) {
t.Errorf("#%d got: %x want: %x", i, out, test.out)
@ -997,7 +997,7 @@ type exported struct {
}
func TestUnexportedStructField(t *testing.T) {
want := asn1.StructuralError{"struct contains unexported fields"}
want := asn1.StructuralError{Msg: "struct contains unexported fields"}
_, err := Marshal(unexported{X: 5, y: 1})
if err != want {

View File

@ -446,7 +446,7 @@ func makeBody(value reflect.Value, params fieldParameters) (e encoder, err error
for i := 0; i < t.NumField(); i++ {
if t.Field(i).PkgPath != "" {
return nil, asn1.StructuralError{"struct contains unexported fields"}
return nil, asn1.StructuralError{Msg: "struct contains unexported fields"}
}
}