]> Cypherpunks repositories - gostls13.git/commitdiff
crypto/openpgp/armor: bug fixes
authorAdam Langley <agl@golang.org>
Thu, 3 Feb 2011 14:19:20 +0000 (09:19 -0500)
committerAdam Langley <agl@golang.org>
Thu, 3 Feb 2011 14:19:20 +0000 (09:19 -0500)
* 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

src/pkg/crypto/openpgp/armor/armor.go
src/pkg/crypto/openpgp/armor/armor_test.go
src/pkg/crypto/openpgp/armor/encode.go

index 97080f6c6d1bec94ba036188a781815f503b7af0..0c5ae9d716c0b3e9aa47b74f645925fc907037be 100644 (file)
@@ -112,7 +112,7 @@ func (l *lineReader) Read(p []byte) (n int, err os.Error) {
                return 0, os.EOF
        }
 
-       if len(line) != 64 {
+       if len(line) > 64 {
                return 0, ArmorCorrupt
        }
 
index e4ffd414b6a6467366fa86c7581360f62f13e04c..9334e94e96cdd01c35180f88b2d81a667bb35ab5 100644 (file)
@@ -34,7 +34,7 @@ func TestDecodeEncode(t *testing.T) {
                t.Error(err)
        }
 
-       if adler32.Checksum(contents) != 0x789d7f00 {
+       if adler32.Checksum(contents) != 0x27b144be {
                t.Errorf("contents: got: %x", contents)
        }
 
@@ -73,13 +73,11 @@ func TestLongHeader(t *testing.T) {
 const armorExample1 = `-----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.4.10 (GNU/Linux)
 
-iQEcBAABAgAGBQJMtFESAAoJEKsQXJGvOPsVj40H/1WW6jaMXv4BW+1ueDSMDwM8
-kx1fLOXbVM5/Kn5LStZNt1jWWnpxdz7eq3uiqeCQjmqUoRde3YbB2EMnnwRbAhpp
-cacnAvy9ZQ78OTxUdNW1mhX5bS6q1MTEJnl+DcyigD70HG/yNNQD7sOPMdYQw0TA
-byQBwmLwmTsuZsrYqB68QyLHI+DUugn+kX6Hd2WDB62DKa2suoIUIHQQCd/ofwB3
-WfCYInXQKKOSxu2YOg2Eb4kLNhSMc1i9uKUWAH+sdgJh7NBgdoE4MaNtBFkHXRvv
-okWuf3+xA9ksp1npSY/mDvgHijmjvtpRDe6iUeqfCn8N9u9CBg8geANgaG8+QA4=
-=wfQG
+iJwEAAECAAYFAk1Fv/0ACgkQo01+GMIMMbsYTwQAiAw+QAaNfY6WBdplZ/uMAccm
+4g+81QPmTSGHnetSb6WBiY13kVzK4HQiZH8JSkmmroMLuGeJwsRTEL4wbjRyUKEt
+p1xwUZDECs234F1xiG5enc5SGlRtP7foLBz9lOsjx+LEcA4sTl5/2eZR9zyFZqWW
+TxRjs+fJCIFuo71xb1g=
+=/teI
 -----END PGP SIGNATURE-----`
 
 const armorLongLine = `-----BEGIN PGP SIGNATURE-----
index 410e734602fa0862105712b79e787b67f6009265..0f7de024127784358e186083c58f1c6b602ca9c4 100644 (file)
@@ -116,6 +116,7 @@ func (e *encoding) Close() (err os.Error) {
        if err != nil {
                return
        }
+       e.breaker.Close()
 
        var checksumBytes [3]byte
        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)
-               if err != nil {
-                       return
-               }
+       _, err = out.Write(newline)
+       if err != nil {
+               return
        }
 
        e := &encoding{