diff options
Diffstat (limited to 'libgo/go/encoding/asn1/marshal.go')
-rw-r--r-- | libgo/go/encoding/asn1/marshal.go | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/libgo/go/encoding/asn1/marshal.go b/libgo/go/encoding/asn1/marshal.go index b2f104b4cbe..67a019db2d4 100644 --- a/libgo/go/encoding/asn1/marshal.go +++ b/libgo/go/encoding/asn1/marshal.go @@ -18,7 +18,7 @@ import ( // A forkableWriter is an in-memory buffer that can be // 'forked' to create new forkableWriters that bracket the // original. After -// pre, post := w.fork(); +// pre, post := w.fork() // the overall sequence of bytes represented is logically w+pre+post. type forkableWriter struct { *bytes.Buffer @@ -410,9 +410,11 @@ func stripTagAndLength(in []byte) []byte { func marshalBody(out *forkableWriter, value reflect.Value, params fieldParameters) (err error) { switch value.Type() { + case flagType: + return nil case timeType: t := value.Interface().(time.Time) - if outsideUTCRange(t) { + if params.timeType == tagGeneralizedTime || outsideUTCRange(t) { return marshalGeneralizedTime(out, t) } else { return marshalUTCTime(out, t) @@ -552,6 +554,10 @@ func marshalField(out *forkableWriter, v reflect.Value, params fieldParameters) } class := classUniversal + if params.timeType != 0 && tag != tagUTCTime { + return StructuralError{"explicit time type given to non-time member"} + } + if params.stringType != 0 && tag != tagPrintableString { return StructuralError{"explicit string type given to non-string member"} } @@ -575,7 +581,7 @@ func marshalField(out *forkableWriter, v reflect.Value, params fieldParameters) tag = params.stringType } case tagUTCTime: - if outsideUTCRange(v.Interface().(time.Time)) { + if params.timeType == tagGeneralizedTime || outsideUTCRange(v.Interface().(time.Time)) { tag = tagGeneralizedTime } } |