From 088135569acd6617c929b64e644e377e316f7df1 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Sun, 23 Jul 2017 01:34:40 +0200 Subject: unexport block --- file/file.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'file/file.go') diff --git a/file/file.go b/file/file.go index 4fde2f3..fa77cd0 100644 --- a/file/file.go +++ b/file/file.go @@ -22,19 +22,19 @@ const ( var ErrComment = errors.New("expected untrusted comment") -// Block represents a encoded signify key or signature +// block represents a encoded signify key or signature // // The encoded form is: // untrusted comment: comment // base64-encoded key // optional message -type Block struct { +type block struct { Comment string Bytes []byte Message []byte // TODO replace with io.ReadCloser } -func decodeBlock(r io.Reader) (*Block, error) { +func decodeBlock(r io.Reader) (*block, error) { buf := bufio.NewReader(r) comment, err := buf.ReadString('\n') if err != nil { @@ -55,7 +55,7 @@ func decodeBlock(r io.Reader) (*Block, error) { if err != nil { return nil, err } - return &Block{ + return &block{ Comment: strings.TrimSpace(comment[len(untrusted):]), Bytes: b, Message: message, @@ -82,28 +82,28 @@ func Decode(r io.Reader, u encoding.BinaryUnmarshaler) (string, []byte, error) { return block.Comment, block.Message, nil } -func encodeBlock(w io.Writer, b *Block) error { +func encodeBlock(w io.Writer, b *block) error { fmt.Fprintln(w, untrusted, b.Comment) fmt.Fprintln(w, base64.StdEncoding.EncodeToString(b.Bytes)) w.Write(b.Message) return nil } -func EncodeFile(fname string, perm os.FileMode, b *Block) error { +func EncodeFile(fname string, perm os.FileMode, u encoding.BinaryMarshaler, comment string, msg []byte) error { fd, err := os.OpenFile(fname, os.O_WRONLY|os.O_CREATE|os.O_EXCL, perm) if err != nil { return err } defer fd.Close() - return encodeBlock(fd, b) + return Encode(fd, u, comment, msg) } -func Encode(w io.Writer, comment string, u encoding.BinaryMarshaler, msg []byte) error { +func Encode(w io.Writer, u encoding.BinaryMarshaler, comment string, msg []byte) error { raw, err := u.MarshalBinary() if err != nil { return err } - b := &Block{ + b := &block{ Comment: comment, Bytes: raw, Message: msg, -- cgit v1.2.3