openpgp/packet: Compact UserAttribute subpacket lengths, fixes signatures.
Necessary to reproduce the same hash for verifying a UserAttribute signature. Reuse and fix defect in serializeSubpacketLength, RFC 4880, Section 4.2.2.2. R=agl CC=golang-dev https://golang.org/cl/13464044
This commit is contained in:
committed by
Adam Langley
parent
ffadfa6648
commit
58b09dec0e
@@ -7,7 +7,6 @@ package packet
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"code.google.com/p/go.crypto/openpgp/errors"
|
"code.google.com/p/go.crypto/openpgp/errors"
|
||||||
"encoding/binary"
|
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
)
|
)
|
||||||
@@ -152,11 +151,9 @@ Truncated:
|
|||||||
|
|
||||||
func (osp *OpaqueSubpacket) Serialize(w io.Writer) (err error) {
|
func (osp *OpaqueSubpacket) Serialize(w io.Writer) (err error) {
|
||||||
buf := make([]byte, 6)
|
buf := make([]byte, 6)
|
||||||
buf[0] = 0xff
|
n := serializeSubpacketLength(buf, len(osp.Contents)+1)
|
||||||
// Header length includes the subtype byte
|
buf[n] = osp.SubType
|
||||||
binary.BigEndian.PutUint32(buf[1:5], uint32(len(osp.Contents)+1))
|
if _, err = w.Write(buf[:n+1]); err != nil {
|
||||||
buf[5] = osp.SubType
|
|
||||||
if _, err = w.Write(buf); err != nil {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
_, err = w.Write(osp.Contents)
|
_, err = w.Write(osp.Contents)
|
||||||
|
|||||||
@@ -344,13 +344,14 @@ func subpacketLengthLength(length int) int {
|
|||||||
|
|
||||||
// serializeSubpacketLength marshals the given length into to.
|
// serializeSubpacketLength marshals the given length into to.
|
||||||
func serializeSubpacketLength(to []byte, length int) int {
|
func serializeSubpacketLength(to []byte, length int) int {
|
||||||
|
// RFC 4880, Section 4.2.2.
|
||||||
if length < 192 {
|
if length < 192 {
|
||||||
to[0] = byte(length)
|
to[0] = byte(length)
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
if length < 16320 {
|
if length < 16320 {
|
||||||
length -= 192
|
length -= 192
|
||||||
to[0] = byte(length >> 8)
|
to[0] = byte((length >> 8) + 192)
|
||||||
to[1] = byte(length)
|
to[1] = byte(length)
|
||||||
return 2
|
return 2
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user