Skip to content

Commit 2a2995c

Browse files
committed
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
1 parent fc5c1f0 commit 2a2995c

File tree

3 files changed

+11
-14
lines changed

3 files changed

+11
-14
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func (l *lineReader) Read(p []byte) (n int, err os.Error) {
112112
return 0, os.EOF
113113
}
114114

115-
if len(line) != 64 {
115+
if len(line) > 64 {
116116
return 0, ArmorCorrupt
117117
}
118118

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func TestDecodeEncode(t *testing.T) {
3434
t.Error(err)
3535
}
3636

37-
if adler32.Checksum(contents) != 0x789d7f00 {
37+
if adler32.Checksum(contents) != 0x27b144be {
3838
t.Errorf("contents: got: %x", contents)
3939
}
4040

@@ -73,13 +73,11 @@ func TestLongHeader(t *testing.T) {
7373
const armorExample1 = `-----BEGIN PGP SIGNATURE-----
7474
Version: GnuPG v1.4.10 (GNU/Linux)
7575
76-
iQEcBAABAgAGBQJMtFESAAoJEKsQXJGvOPsVj40H/1WW6jaMXv4BW+1ueDSMDwM8
77-
kx1fLOXbVM5/Kn5LStZNt1jWWnpxdz7eq3uiqeCQjmqUoRde3YbB2EMnnwRbAhpp
78-
cacnAvy9ZQ78OTxUdNW1mhX5bS6q1MTEJnl+DcyigD70HG/yNNQD7sOPMdYQw0TA
79-
byQBwmLwmTsuZsrYqB68QyLHI+DUugn+kX6Hd2WDB62DKa2suoIUIHQQCd/ofwB3
80-
WfCYInXQKKOSxu2YOg2Eb4kLNhSMc1i9uKUWAH+sdgJh7NBgdoE4MaNtBFkHXRvv
81-
okWuf3+xA9ksp1npSY/mDvgHijmjvtpRDe6iUeqfCn8N9u9CBg8geANgaG8+QA4=
82-
=wfQG
76+
iJwEAAECAAYFAk1Fv/0ACgkQo01+GMIMMbsYTwQAiAw+QAaNfY6WBdplZ/uMAccm
77+
4g+81QPmTSGHnetSb6WBiY13kVzK4HQiZH8JSkmmroMLuGeJwsRTEL4wbjRyUKEt
78+
p1xwUZDECs234F1xiG5enc5SGlRtP7foLBz9lOsjx+LEcA4sTl5/2eZR9zyFZqWW
79+
TxRjs+fJCIFuo71xb1g=
80+
=/teI
8381
-----END PGP SIGNATURE-----`
8482

8583
const armorLongLine = `-----BEGIN PGP SIGNATURE-----

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ func (e *encoding) Close() (err os.Error) {
116116
if err != nil {
117117
return
118118
}
119+
e.breaker.Close()
119120

120121
var checksumBytes [3]byte
121122
checksumBytes[0] = byte(e.crc >> 16)
@@ -144,11 +145,9 @@ func Encode(out io.Writer, blockType string, headers map[string]string) (w io.Wr
144145
}
145146
}
146147

147-
if len(headers) > 0 {
148-
_, err := out.Write(newline)
149-
if err != nil {
150-
return
151-
}
148+
_, err = out.Write(newline)
149+
if err != nil {
150+
return
152151
}
153152

154153
e := &encoding{

0 commit comments

Comments
 (0)