1
0
mirror of https://github.com/golang/go synced 2024-11-25 02:07:58 -07:00

crypto/openpgp/armor: bug fixes

* Don't require lines to be full.
* Don't forget to flush the line buffer.
* Update the test so that it doesn't happen to include only full lines
  in order to test the above.
* Always write the line after the header as GNUPG expects it.

R=bradfitzgo
CC=golang-dev
https://golang.org/cl/4124043
This commit is contained in:
Adam Langley 2011-02-03 09:19:20 -05:00
parent fc5c1f0a18
commit 2a2995cec8
3 changed files with 11 additions and 14 deletions

View File

@ -112,7 +112,7 @@ func (l *lineReader) Read(p []byte) (n int, err os.Error) {
return 0, os.EOF return 0, os.EOF
} }
if len(line) != 64 { if len(line) > 64 {
return 0, ArmorCorrupt return 0, ArmorCorrupt
} }

View File

@ -34,7 +34,7 @@ func TestDecodeEncode(t *testing.T) {
t.Error(err) t.Error(err)
} }
if adler32.Checksum(contents) != 0x789d7f00 { if adler32.Checksum(contents) != 0x27b144be {
t.Errorf("contents: got: %x", contents) t.Errorf("contents: got: %x", contents)
} }
@ -73,13 +73,11 @@ func TestLongHeader(t *testing.T) {
const armorExample1 = `-----BEGIN PGP SIGNATURE----- const armorExample1 = `-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux) Version: GnuPG v1.4.10 (GNU/Linux)
iQEcBAABAgAGBQJMtFESAAoJEKsQXJGvOPsVj40H/1WW6jaMXv4BW+1ueDSMDwM8 iJwEAAECAAYFAk1Fv/0ACgkQo01+GMIMMbsYTwQAiAw+QAaNfY6WBdplZ/uMAccm
kx1fLOXbVM5/Kn5LStZNt1jWWnpxdz7eq3uiqeCQjmqUoRde3YbB2EMnnwRbAhpp 4g+81QPmTSGHnetSb6WBiY13kVzK4HQiZH8JSkmmroMLuGeJwsRTEL4wbjRyUKEt
cacnAvy9ZQ78OTxUdNW1mhX5bS6q1MTEJnl+DcyigD70HG/yNNQD7sOPMdYQw0TA p1xwUZDECs234F1xiG5enc5SGlRtP7foLBz9lOsjx+LEcA4sTl5/2eZR9zyFZqWW
byQBwmLwmTsuZsrYqB68QyLHI+DUugn+kX6Hd2WDB62DKa2suoIUIHQQCd/ofwB3 TxRjs+fJCIFuo71xb1g=
WfCYInXQKKOSxu2YOg2Eb4kLNhSMc1i9uKUWAH+sdgJh7NBgdoE4MaNtBFkHXRvv =/teI
okWuf3+xA9ksp1npSY/mDvgHijmjvtpRDe6iUeqfCn8N9u9CBg8geANgaG8+QA4=
=wfQG
-----END PGP SIGNATURE-----` -----END PGP SIGNATURE-----`
const armorLongLine = `-----BEGIN PGP SIGNATURE----- const armorLongLine = `-----BEGIN PGP SIGNATURE-----

View File

@ -116,6 +116,7 @@ func (e *encoding) Close() (err os.Error) {
if err != nil { if err != nil {
return return
} }
e.breaker.Close()
var checksumBytes [3]byte var checksumBytes [3]byte
checksumBytes[0] = byte(e.crc >> 16) checksumBytes[0] = byte(e.crc >> 16)
@ -144,11 +145,9 @@ func Encode(out io.Writer, blockType string, headers map[string]string) (w io.Wr
} }
} }
if len(headers) > 0 { _, err = out.Write(newline)
_, err := out.Write(newline) if err != nil {
if err != nil { return
return
}
} }
e := &encoding{ e := &encoding{