Skip to content

Commit 2d2c789

Browse files
authored
feat(cleartext): Do not include line ending separator in plaintext (#242)
The cleartext plaintext should exclude the line ending separator defined by the Cleartext Signed Message Structure. The line ending separator change was made to enhance interoperability, as the original implementation was non-deterministic—potentially adding a newline when the input lacked one. GopenPGP removes the additional line ending separator, but this could be directly handled by go-crypto.
1 parent f8b3f21 commit 2d2c789

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

openpgp/clearsign/clearsign.go

+1
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ func Decode(data []byte) (b *Block, rest []byte) {
173173
b.Plaintext = append(b.Plaintext, line...)
174174
b.Plaintext = append(b.Plaintext, lf)
175175
}
176+
b.Plaintext = b.Plaintext[:len(b.Plaintext)-1]
176177

177178
// We want to find the extent of the armored data (including any newlines at
178179
// the end).

openpgp/clearsign/clearsign_test.go

+15-15
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ func testParse(t *testing.T, input []byte, expected, expectedPlaintext string) {
5858
}
5959

6060
func TestParse(t *testing.T) {
61-
testParse(t, clearsignInput, "Hello world\r\nline 2", "Hello world\nline 2\n")
62-
testParse(t, clearsignInput2, "\r\n\r\n(This message has a couple of blank lines at the start and end.)\r\n\r\n", "\n\n(This message has a couple of blank lines at the start and end.)\n\n\n")
61+
testParse(t, clearsignInput, "Hello world\r\nline 2", "Hello world\nline 2")
62+
testParse(t, clearsignInput2, "\r\n\r\n(This message has a couple of blank lines at the start and end.)\r\n\r\n", "\n\n(This message has a couple of blank lines at the start and end.)\n\n")
6363
}
6464

6565
func TestParseWithNoNewlineAtEnd(t *testing.T) {
@@ -77,21 +77,21 @@ func TestParseWithNoNewlineAtEnd(t *testing.T) {
7777
var signingTests = []struct {
7878
in, signed, plaintext string
7979
}{
80-
{"", "", "\n"},
81-
{"a", "a", "a\n"},
82-
{"a\n", "a\r\n", "a\n\n"},
83-
{"-a\n", "-a\r\n", "-a\n\n"},
84-
{"--a\nb", "--a\r\nb", "--a\nb\n"},
80+
{"", "", ""},
81+
{"a", "a", "a"},
82+
{"a\n", "a\r\n", "a\n"},
83+
{"-a\n", "-a\r\n", "-a\n"},
84+
{"--a\nb", "--a\r\nb", "--a\nb"},
8585
// leading whitespace
86-
{" a\n", " a\r\n", " a\n\n"},
87-
{" a\n", " a\r\n", " a\n\n"},
86+
{" a\n", " a\r\n", " a\n"},
87+
{" a\n", " a\r\n", " a\n"},
8888
// trailing whitespace (should be stripped)
89-
{"a \n", "a\r\n", "a\n\n"},
90-
{"a ", "a", "a\n"},
91-
{" \n", "\r\n", "\n\n"},
92-
{" ", "", "\n"},
93-
{"a\n \n \nb\n", "a\r\n\r\n\r\nb\r\n", "a\n\n\nb\n\n"},
94-
{"a\n \n \nb\n", "a\r\n\r\n\r\nb\r\n", "a\n\n\nb\n\n"},
89+
{"a \n", "a\r\n", "a\n"},
90+
{"a ", "a", "a"},
91+
{" \n", "\r\n", "\n"},
92+
{" ", "", ""},
93+
{"a\n \n \nb\n", "a\r\n\r\n\r\nb\r\n", "a\n\n\nb\n"},
94+
{"a\n \n \nb\n", "a\r\n\r\n\r\nb\r\n", "a\n\n\nb\n"},
9595
}
9696

9797
func TestVerifyV6(t *testing.T) {

0 commit comments

Comments
 (0)