aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2017-07-26 22:08:26 +0200
committerDimitri Sokolyuk <demon@dim13.org>2017-07-26 22:08:26 +0200
commitfd253710b5161822275ef3211d5e68b462d1a548 (patch)
treed16dd619c06f713e450005be0883f30136a30126
parent6b387241e474194ad030b500903c030ba70cc63b (diff)
untrusted
-rw-r--r--file/file.go9
-rw-r--r--file/file_test.go2
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)