diff --git a/internal/testdata/robtest.ps1.minisig b/internal/testdata/robtest.ps1.minisig new file mode 100644 index 0000000..7d09aa4 --- /dev/null +++ b/internal/testdata/robtest.ps1.minisig @@ -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== diff --git a/signature.go b/signature.go index 3e24b37..e49900d 100644 --- a/signature.go +++ b/signature.go @@ -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: ") { diff --git a/signature_test.go b/signature_test.go index 30a0322..aa1f3e3 100644 --- a/signature_test.go +++ b/signature_test.go @@ -4,7 +4,10 @@ package minisign -import "testing" +import ( + "strings" + "testing" +) func TestEqualSignature(t *testing.T) { for i, test := range equalSignatureTests { @@ -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