diff options
| author | Adam Langley <agl@golang.org> | 2011-03-10 10:14:31 -0500 |
|---|---|---|
| committer | Adam Langley <agl@golang.org> | 2011-03-10 10:14:31 -0500 |
| commit | dd5adcc3c3fdc36e34df72ece0bc56d0cf7c38e9 (patch) | |
| tree | 6d50346044b98ea06124a48d6dccf950528cc654 /src/pkg/crypto/openpgp/packet | |
| parent | daf33c3ebeb40300957cc6fa0fb8c350ae7d26f9 (diff) | |
| download | go-dd5adcc3c3fdc36e34df72ece0bc56d0cf7c38e9.tar.xz | |
crypto/openpgp: bug fixes and fix misnamed function.
R=rsc, bradfitzwork
CC=golang-dev
https://golang.org/cl/4244066
Diffstat (limited to 'src/pkg/crypto/openpgp/packet')
| -rw-r--r-- | src/pkg/crypto/openpgp/packet/packet.go | 16 | ||||
| -rw-r--r-- | src/pkg/crypto/openpgp/packet/packet_test.go | 20 |
2 files changed, 28 insertions, 8 deletions
diff --git a/src/pkg/crypto/openpgp/packet/packet.go b/src/pkg/crypto/openpgp/packet/packet.go index 269603ba49..aacbb666ec 100644 --- a/src/pkg/crypto/openpgp/packet/packet.go +++ b/src/pkg/crypto/openpgp/packet/packet.go @@ -169,7 +169,7 @@ func readHeader(r io.Reader) (tag packetType, length int64, contents io.Reader, // serialiseHeader writes an OpenPGP packet header to w. See RFC 4880, section // 4.2. func serialiseHeader(w io.Writer, ptype packetType, length int) (err os.Error) { - var buf [5]byte + var buf [6]byte var n int buf[0] = 0x80 | 0x40 | byte(ptype) @@ -178,16 +178,16 @@ func serialiseHeader(w io.Writer, ptype packetType, length int) (err os.Error) { n = 2 } else if length < 8384 { length -= 192 - buf[1] = byte(length >> 8) + buf[1] = 192 + byte(length>>8) buf[2] = byte(length) n = 3 } else { - buf[0] = 255 - buf[1] = byte(length >> 24) - buf[2] = byte(length >> 16) - buf[3] = byte(length >> 8) - buf[4] = byte(length) - n = 5 + buf[1] = 255 + buf[2] = byte(length >> 24) + buf[3] = byte(length >> 16) + buf[4] = byte(length >> 8) + buf[5] = byte(length) + n = 6 } _, err = w.Write(buf[:n]) diff --git a/src/pkg/crypto/openpgp/packet/packet_test.go b/src/pkg/crypto/openpgp/packet/packet_test.go index 6789d2abc7..40c6b67d34 100644 --- a/src/pkg/crypto/openpgp/packet/packet_test.go +++ b/src/pkg/crypto/openpgp/packet/packet_test.go @@ -190,3 +190,23 @@ func TestReadHeader(t *testing.T) { } } } + +func TestSerialiseHeader(t *testing.T) { + tag := packetTypePublicKey + lengths := []int{0, 1, 2, 64, 192, 193, 8000, 8384, 8385, 10000} + + for _, length := range lengths { + buf := bytes.NewBuffer(nil) + serialiseHeader(buf, tag, length) + tag2, length2, _, err := readHeader(buf) + if err != nil { + t.Errorf("length %d, err: %s", length, err) + } + if tag2 != tag { + t.Errorf("length %d, tag incorrect (got %d, want %d)", length, tag2, tag) + } + if int(length2) != length { + t.Errorf("length %d, length incorrect (got %d)", length, length2) + } + } +} |
