From fd253710b5161822275ef3211d5e68b462d1a548 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Wed, 26 Jul 2017 22:08:26 +0200 Subject: untrusted --- file/file.go | 9 +++++---- file/file_test.go | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/file/file.go b/file/file.go index 5b3fbcf..c6fb266 100644 --- a/file/file.go +++ b/file/file.go @@ -18,7 +18,7 @@ const ( ModeSec os.FileMode = 0600 ModePub os.FileMode = 0644 ModeSig os.FileMode = 0644 - untrusted = "untrusted comment:" + untrusted = "untrusted comment: " ) // Original Error: "invalid comment in %s; must start with 'untrusted comment: '" @@ -53,7 +53,8 @@ func Decode(r io.Reader, u encoding.BinaryUnmarshaler) (string, []byte, error) { if !strings.HasPrefix(comment, untrusted) { return "", nil, ErrComment } - comment = strings.TrimSpace(comment[len(untrusted):]) + comment = strings.TrimPrefix(comment, untrusted) + comment = strings.TrimSpace(comment) raw, err := buf.ReadString('\n') if err != nil { @@ -89,8 +90,8 @@ func Encode(w io.Writer, u encoding.BinaryMarshaler, comment string, msg []byte) if err != nil { return err } - fmt.Fprintln(w, untrusted, comment) - fmt.Fprintln(w, base64.StdEncoding.EncodeToString(raw)) + fmt.Fprintf(w, "%s%s\n", untrusted, comment) + fmt.Fprintf(w, "%s\n", base64.StdEncoding.EncodeToString(raw)) w.Write(msg) return nil } diff --git a/file/file_test.go b/file/file_test.go index 3bf8f1f..5a2aa8d 100644 --- a/file/file_test.go +++ b/file/file_test.go @@ -11,7 +11,7 @@ func (moc) MarshalBinary() ([]byte, error) { return nil, nil } func (moc) UnmarshalBinary(_ []byte) error { return nil } func TestSig(t *testing.T) { - comment := "comment" + comment := "untrusted comment: comment" message := []byte{'t', 'e', 's', 't'} buf := new(bytes.Buffer) err := Encode(buf, moc{}, comment, message) -- cgit v1.2.3