1
0
mirror of https://github.com/golang/go synced 2024-11-21 21:44:40 -07:00

asn1: fix marshalling of empty optional RawValues

This fixes creation of X509 certificates with
RSA keys. (Broken by e5ecc416f2fd)

R=agl
CC=golang-dev
https://golang.org/cl/4553052
This commit is contained in:
Mikkel Krautz 2011-06-01 12:54:16 -04:00 committed by Adam Langley
parent 2c4edb0eea
commit 2899535de5
2 changed files with 9 additions and 7 deletions

View File

@ -458,11 +458,12 @@ func marshalField(out *forkableWriter, v reflect.Value, params fieldParameters)
return marshalField(out, v.Elem(), params) return marshalField(out, v.Elem(), params)
} }
if params.optional && reflect.DeepEqual(v.Interface(), reflect.Zero(v.Type()).Interface()) {
return
}
if v.Type() == rawValueType { if v.Type() == rawValueType {
rv := v.Interface().(RawValue) rv := v.Interface().(RawValue)
if rv.Class == 0 && rv.Tag == 0 && len(rv.Bytes) == 0 && params.optional {
return
}
err = marshalTagAndLength(out, tagAndLength{rv.Class, rv.Tag, len(rv.Bytes), rv.IsCompound}) err = marshalTagAndLength(out, tagAndLength{rv.Class, rv.Tag, len(rv.Bytes), rv.IsCompound})
if err != nil { if err != nil {
return return
@ -471,10 +472,6 @@ func marshalField(out *forkableWriter, v reflect.Value, params fieldParameters)
return return
} }
if params.optional && reflect.DeepEqual(v.Interface(), reflect.Zero(v.Type()).Interface()) {
return
}
tag, isCompound, ok := getUniversalType(v.Type()) tag, isCompound, ok := getUniversalType(v.Type())
if !ok { if !ok {
err = StructuralError{fmt.Sprintf("unknown Go type: %v", v.Type())} err = StructuralError{fmt.Sprintf("unknown Go type: %v", v.Type())}

View File

@ -45,6 +45,10 @@ type printableStringTest struct {
A string "printable" A string "printable"
} }
type optionalRawValueTest struct {
A RawValue "optional"
}
type testSET []int type testSET []int
func setPST(t *time.Time) *time.Time { func setPST(t *time.Time) *time.Time {
@ -102,6 +106,7 @@ var marshalTests = []marshalTest{
"7878787878787878787878787878787878787878787878787878787878787878", "7878787878787878787878787878787878787878787878787878787878787878",
}, },
{ia5StringTest{"test"}, "3006160474657374"}, {ia5StringTest{"test"}, "3006160474657374"},
{optionalRawValueTest{}, "3000"},
{printableStringTest{"test"}, "3006130474657374"}, {printableStringTest{"test"}, "3006130474657374"},
{printableStringTest{"test*"}, "30071305746573742a"}, {printableStringTest{"test*"}, "30071305746573742a"},
{rawContentsStruct{nil, 64}, "3003020140"}, {rawContentsStruct{nil, 64}, "3003020140"},