Commit e7cceb85 authored by Adam Langley's avatar Adam Langley

asn1: fix marshaling of structures with >1 elements.

Fixes #515.

R=rsc
CC=golang-dev
https://golang.org/cl/184079
parent 72b97e46
......@@ -29,6 +29,9 @@ func newForkableWriter() *forkableWriter {
}
func (f *forkableWriter) fork() (pre, post *forkableWriter) {
if f.pre != nil || f.post != nil {
panic("have already forked")
}
f.pre = newForkableWriter()
f.post = newForkableWriter()
return f.pre, f.post
......@@ -61,7 +64,7 @@ func (f *forkableWriter) writeTo(out io.Writer) (n int, err os.Error) {
}
}
if f.pre != nil {
if f.post != nil {
nn, err = f.post.writeTo(out)
n += nn
}
......@@ -297,7 +300,9 @@ func marshalBody(out *forkableWriter, value reflect.Value, params fieldParameter
case *reflect.StructValue:
t := v.Type().(*reflect.StructType)
for i := 0; i < t.NumField(); i++ {
err = marshalField(out, v.Field(i), parseFieldParameters(t.Field(i).Tag))
var pre *forkableWriter
pre, out = out.fork()
err = marshalField(pre, v.Field(i), parseFieldParameters(t.Field(i).Tag))
if err != nil {
return
}
......
......@@ -15,6 +15,11 @@ type intStruct struct {
A int
}
type twoIntStruct struct {
A int
B int
}
type nestedStruct struct {
A intStruct
}
......@@ -48,6 +53,7 @@ func setPST(t *time.Time) *time.Time {
var marshalTests = []marshalTest{
marshalTest{10, "02010a"},
marshalTest{intStruct{64}, "3003020140"},
marshalTest{twoIntStruct{64, 65}, "3006020140020141"},
marshalTest{nestedStruct{intStruct{127}}, "3005300302017f"},
marshalTest{[]byte{1, 2, 3}, "0403010203"},
marshalTest{implicitTagTest{64}, "3003850140"},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment