Commit e2c7e53d authored by Nicholas Waples's avatar Nicholas Waples Committed by Adam Langley

asn1 incorrectly encoded signed integers. When determining the

encoded length it was not taking into account the sign bit.

Fixes #997.

R=agl1, gri
CC=golang-dev
https://golang.org/cl/1870047
parent bc4a9caa
...@@ -123,13 +123,20 @@ func marshalInt64(out *forkableWriter, i int64) (err os.Error) { ...@@ -123,13 +123,20 @@ func marshalInt64(out *forkableWriter, i int64) (err os.Error) {
} }
func int64Length(i int64) (numBytes int) { func int64Length(i int64) (numBytes int) {
if i == 0 { numBytes = 1
return 1
if i > 0 {
for i > 127 {
numBytes++
i >>= 8
}
} }
for i > 0 { if i < 0 {
numBytes++ for i < -128 {
i >>= 8 numBytes++
i >>= 8
}
} }
return return
......
...@@ -59,6 +59,10 @@ type marshalTest struct { ...@@ -59,6 +59,10 @@ type marshalTest struct {
var marshalTests = []marshalTest{ var marshalTests = []marshalTest{
marshalTest{10, "02010a"}, marshalTest{10, "02010a"},
marshalTest{127, "02017f"},
marshalTest{128, "02020080"},
marshalTest{-128, "020180"},
marshalTest{-129, "0202ff7f"},
marshalTest{intStruct{64}, "3003020140"}, marshalTest{intStruct{64}, "3003020140"},
marshalTest{twoIntStruct{64, 65}, "3006020140020141"}, marshalTest{twoIntStruct{64, 65}, "3006020140020141"},
marshalTest{nestedStruct{intStruct{127}}, "3005300302017f"}, marshalTest{nestedStruct{intStruct{127}}, "3005300302017f"},
......
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