aboutsummaryrefslogtreecommitdiff
path: root/file.go
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2016-10-23 21:05:07 +0200
committerDimitri Sokolyuk <demon@dim13.org>2016-10-23 21:05:07 +0200
commit6e80b3fb8d5bfd948a46a9bf48730e460471af56 (patch)
treebb5caf4eb536d1ccce9bb1aa55b40938eae8cbba /file.go
parent49ca0b5af56dea12695c3a83ad5a4bb80992d51b (diff)
Cleanup
Diffstat (limited to 'file.go')
-rw-r--r--file.go27
1 files changed, 19 insertions, 8 deletions
diff --git a/file.go b/file.go
index 68737ad..e8218d8 100644
--- a/file.go
+++ b/file.go
@@ -25,31 +25,42 @@ const (
sigFrom = "signature from %s"
)
+func checkComment(comment string) error {
+ // compatibility with original version
+ if len(comment) > 1024 {
+ return errors.New("comment line to long")
+ }
+ if !strings.HasPrefix(comment, commentHdr) {
+ return errors.New("expected untrusted comment")
+ }
+ return nil
+}
+
func Parse(r io.Reader) (File, error) {
buf := bufio.NewReader(r)
+
comment, err := buf.ReadString('\n')
if err != nil {
return File{}, err
}
- if !strings.HasPrefix(comment, commentHdr) {
- return File{}, errors.New("expected untrusted header")
- }
- // Backward compatibility with original signify
- if len(comment) > 1024 {
- return File{}, errors.New("comment line too long")
+ if err := checkComment(comment); err != nil {
+ return File{}, err
}
comment = comment[len(commentHdr):]
+
b64, err := buf.ReadBytes('\n')
if err != nil {
return File{}, err
}
+
body, err := ioutil.ReadAll(buf)
if err != nil {
return File{}, err
}
+
return File{
- Comment: strings.TrimRight(comment, "\r\n"),
- B64: bytes.TrimRight(b64, "\r\n"),
+ Comment: strings.TrimSpace(comment),
+ B64: bytes.TrimSpace(b64),
Body: body,
}, nil
}