aboutsummaryrefslogtreecommitdiff
path: root/file
diff options
context:
space:
mode:
Diffstat (limited to 'file')
-rw-r--r--file/file.go14
1 files changed, 13 insertions, 1 deletions
diff --git a/file/file.go b/file/file.go
index e954604..5b3fbcf 100644
--- a/file/file.go
+++ b/file/file.go
@@ -3,6 +3,7 @@ package file
import (
"bufio"
+ "bytes"
"encoding"
"encoding/base64"
"errors"
@@ -20,7 +21,8 @@ const (
untrusted = "untrusted comment:"
)
-var ErrComment = errors.New("expected untrusted comment")
+// Original Error: "invalid comment in %s; must start with 'untrusted comment: '"
+var ErrComment = errors.New("comment must start with 'untrusted comment: '")
func DecodeFile(fname string, u encoding.BinaryUnmarshaler) (string, []byte, error) {
fd, err := os.Open(fname)
@@ -31,6 +33,16 @@ func DecodeFile(fname string, u encoding.BinaryUnmarshaler) (string, []byte, err
return Decode(fd, u)
}
+func DecodeString(data string, u encoding.BinaryUnmarshaler) (string, []byte, error) {
+ r := strings.NewReader(data)
+ return Decode(r, u)
+}
+
+func DecodeBytes(data []byte, u encoding.BinaryUnmarshaler) (string, []byte, error) {
+ r := bytes.NewReader(data)
+ return Decode(r, u)
+}
+
func Decode(r io.Reader, u encoding.BinaryUnmarshaler) (string, []byte, error) {
buf := bufio.NewReader(r)