8000 trim carriage-return at the end of signature comments by aead · Pull Request #8 · aead/minisign · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions internal/testdata/robtest.ps1.minisig
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
untrusted comment: signature from minisign secret key
RWQ3ly9IPenQ6XE4gvV0tpJPSRdw/Si+Q4r97LbpLj0Hb3sV+XFydynJg3iFT2PjIlE3xViNOmFT9XrIoidedDr41+Ly0AYbUQg=
trusted comment: timestamp:1617721023 file:robtest.ps1
HkxuqHSvipJo/unNKgDS+JGDB0+Q5d8nOeoJ0NGOnKBNsNdvAj8FWf7fhaPV7mzRJ1ooLvYpI0yUsD7lpaDwBQ==
4 changes: 2 additions & 2 deletions signature.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ func (s *Signature) UnmarshalText(text []byte) error {
}

var (
untrustedComment = segments[0]
untrustedComment = strings.TrimRight(segments[0], "\r")
encodedSignature = segments[1]
trustedComment = segments[2]
trustedComment = strings.TrimRight(segments[2], "\r")
encodedCommentSignature = segments[3]
)
if !strings.HasPrefix(untrustedComment, "untrusted comment: ") {
Expand Down
18 changes: 17 additions & 1 deletion signature_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

package minisign

import "testing"
import (
"strings"
"testing"
)

func TestEqualSignature(t *testing.T) {
for i, test := range equalSignatureTests {
Expand Down Expand Up @@ -64,6 +67,19 @@ func TestUnmarshalSignature(t *testing.T) {
}
}

func TestSignatureCarriageReturn(t *testing.T) {
signature, err := SignatureFromFile("./internal/testdata/robtest.ps1.minisig")
if err != nil {
t.Fatalf("Failed to read signature from file: %v", err)
}
if strings.HasSuffix(signature.UntrustedComment, "\r") {
t.Fatal("Untrusted comment ends with a carriage return")
}
if strings.HasSuffix(signature.TrustedComment, "\r") {
t.Fatal("Trusted comment ends with a carriage return")
}
}

var equalSignatureTests = []struct {
A, B Signature
Equal bool
Expand Down
0