Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
e7cceb85
Commit
e7cceb85
authored
Jan 12, 2010
by
Adam Langley
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
asn1: fix marshaling of structures with >1 elements.
Fixes #515. R=rsc CC=golang-dev
https://golang.org/cl/184079
parent
72b97e46
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
2 deletions
+13
-2
marshal.go
src/pkg/asn1/marshal.go
+7
-2
marshal_test.go
src/pkg/asn1/marshal_test.go
+6
-0
No files found.
src/pkg/asn1/marshal.go
View file @
e7cceb85
...
@@ -29,6 +29,9 @@ func newForkableWriter() *forkableWriter {
...
@@ -29,6 +29,9 @@ func newForkableWriter() *forkableWriter {
}
}
func
(
f
*
forkableWriter
)
fork
()
(
pre
,
post
*
forkableWriter
)
{
func
(
f
*
forkableWriter
)
fork
()
(
pre
,
post
*
forkableWriter
)
{
if
f
.
pre
!=
nil
||
f
.
post
!=
nil
{
panic
(
"have already forked"
)
}
f
.
pre
=
newForkableWriter
()
f
.
pre
=
newForkableWriter
()
f
.
post
=
newForkableWriter
()
f
.
post
=
newForkableWriter
()
return
f
.
pre
,
f
.
post
return
f
.
pre
,
f
.
post
...
@@ -61,7 +64,7 @@ func (f *forkableWriter) writeTo(out io.Writer) (n int, err os.Error) {
...
@@ -61,7 +64,7 @@ func (f *forkableWriter) writeTo(out io.Writer) (n int, err os.Error) {
}
}
}
}
if
f
.
p
re
!=
nil
{
if
f
.
p
ost
!=
nil
{
nn
,
err
=
f
.
post
.
writeTo
(
out
)
nn
,
err
=
f
.
post
.
writeTo
(
out
)
n
+=
nn
n
+=
nn
}
}
...
@@ -297,7 +300,9 @@ func marshalBody(out *forkableWriter, value reflect.Value, params fieldParameter
...
@@ -297,7 +300,9 @@ func marshalBody(out *forkableWriter, value reflect.Value, params fieldParameter
case
*
reflect
.
StructValue
:
case
*
reflect
.
StructValue
:
t
:=
v
.
Type
()
.
(
*
reflect
.
StructType
)
t
:=
v
.
Type
()
.
(
*
reflect
.
StructType
)
for
i
:=
0
;
i
<
t
.
NumField
();
i
++
{
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
{
if
err
!=
nil
{
return
return
}
}
...
...
src/pkg/asn1/marshal_test.go
View file @
e7cceb85
...
@@ -15,6 +15,11 @@ type intStruct struct {
...
@@ -15,6 +15,11 @@ type intStruct struct {
A
int
A
int
}
}
type
twoIntStruct
struct
{
A
int
B
int
}
type
nestedStruct
struct
{
type
nestedStruct
struct
{
A
intStruct
A
intStruct
}
}
...
@@ -48,6 +53,7 @@ func setPST(t *time.Time) *time.Time {
...
@@ -48,6 +53,7 @@ func setPST(t *time.Time) *time.Time {
var
marshalTests
=
[]
marshalTest
{
var
marshalTests
=
[]
marshalTest
{
marshalTest
{
10
,
"02010a"
},
marshalTest
{
10
,
"02010a"
},
marshalTest
{
intStruct
{
64
},
"3003020140"
},
marshalTest
{
intStruct
{
64
},
"3003020140"
},
marshalTest
{
twoIntStruct
{
64
,
65
},
"3006020140020141"
},
marshalTest
{
nestedStruct
{
intStruct
{
127
}},
"3005300302017f"
},
marshalTest
{
nestedStruct
{
intStruct
{
127
}},
"3005300302017f"
},
marshalTest
{[]
byte
{
1
,
2
,
3
},
"0403010203"
},
marshalTest
{[]
byte
{
1
,
2
,
3
},
"0403010203"
},
marshalTest
{
implicitTagTest
{
64
},
"3003850140"
},
marshalTest
{
implicitTagTest
{
64
},
"3003850140"
},
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment