aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikkel Krautz <mikkel@krautz.dk>2011-06-01 12:54:16 -0400
committerAdam Langley <agl@golang.org>2011-06-01 12:54:16 -0400
commit2899535de5a343b645ebaddca4147e34d764b8a5 (patch)
tree295f5c8184eac5aec1cd59091e218fbed4469370
parent2c4edb0eea6503da73eec69261b2771ad0c9d973 (diff)
downloadgo-2899535de5a343b645ebaddca4147e34d764b8a5.tar.gz
go-2899535de5a343b645ebaddca4147e34d764b8a5.zip
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
-rw-r--r--src/pkg/asn1/marshal.go11
-rw-r--r--src/pkg/asn1/marshal_test.go5
2 files changed, 9 insertions, 7 deletions
diff --git a/src/pkg/asn1/marshal.go b/src/pkg/asn1/marshal.go
index 771ac28243..7212c91ef9 100644
--- a/src/pkg/asn1/marshal.go
+++ b/src/pkg/asn1/marshal.go
@@ -458,11 +458,12 @@ func marshalField(out *forkableWriter, v reflect.Value, params fieldParameters)
return marshalField(out, v.Elem(), params)
}
+ if params.optional && reflect.DeepEqual(v.Interface(), reflect.Zero(v.Type()).Interface()) {
+ return
+ }
+
if v.Type() == rawValueType {
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})
if err != nil {
return
@@ -471,10 +472,6 @@ func marshalField(out *forkableWriter, v reflect.Value, params fieldParameters)
return
}
- if params.optional && reflect.DeepEqual(v.Interface(), reflect.Zero(v.Type()).Interface()) {
- return
- }
-
tag, isCompound, ok := getUniversalType(v.Type())
if !ok {
err = StructuralError{fmt.Sprintf("unknown Go type: %v", v.Type())}
diff --git a/src/pkg/asn1/marshal_test.go b/src/pkg/asn1/marshal_test.go
index cd165d2035..a9517634d8 100644
--- a/src/pkg/asn1/marshal_test.go
+++ b/src/pkg/asn1/marshal_test.go
@@ -45,6 +45,10 @@ type printableStringTest struct {
A string "printable"
}
+type optionalRawValueTest struct {
+ A RawValue "optional"
+}
+
type testSET []int
func setPST(t *time.Time) *time.Time {
@@ -102,6 +106,7 @@ var marshalTests = []marshalTest{
"7878787878787878787878787878787878787878787878787878787878787878",
},
{ia5StringTest{"test"}, "3006160474657374"},
+ {optionalRawValueTest{}, "3000"},
{printableStringTest{"test"}, "3006130474657374"},
{printableStringTest{"test*"}, "30071305746573742a"},
{rawContentsStruct{nil, 64}, "3003020140"},