aboutsummaryrefslogtreecommitdiff
path: root/file.go
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2017-04-16 23:22:50 +0200
committerDimitri Sokolyuk <demon@dim13.org>2017-04-16 23:22:50 +0200
commit6c1978e53160fea0700cd2f3044d48ea2eddbbb5 (patch)
treed71acf8db7f05b6462f20a7c67ee555c649df3ef /file.go
parent2fecd5783f11680b8f95b9e1a0b9db1bc2e305d1 (diff)
Move base64 out of key representation to file container
Diffstat (limited to 'file.go')
-rw-r--r--file.go23
1 files changed, 14 insertions, 9 deletions
diff --git a/file.go b/file.go
index 4f72542..db2bd82 100644
--- a/file.go
+++ b/file.go
@@ -3,6 +3,7 @@ package main
import (
"bufio"
"bytes"
+ "encoding/base64"
"errors"
"fmt"
"io"
@@ -13,8 +14,8 @@ import (
type File struct {
Comment string
- B64 []byte
- Body []byte
+ RawKey []byte
+ Message []byte
}
const (
@@ -46,15 +47,19 @@ func (f *File) ReadFrom(r io.Reader) error {
if err := checkComment(comment); err != nil {
return err
}
- f.Comment = strings.TrimSpace(comment[len(commentHdr):])
+ f.Comment = strings.TrimSpace(comment[len(commentHdr)+1:])
- b64, err := buf.ReadBytes('\n')
+ b64, err := buf.ReadString('\n')
if err != nil {
return err
}
- f.B64 = bytes.TrimSpace(b64)
- f.Body, err = ioutil.ReadAll(buf)
+ f.RawKey, err = base64.StdEncoding.DecodeString(b64)
+ if err != nil {
+ return err
+ }
+
+ f.Message, err = ioutil.ReadAll(buf)
if err != nil {
return err
}
@@ -89,9 +94,9 @@ func (f File) Bytes() ([]byte, error) {
func (f File) WriteTo(w io.Writer) error {
fmt.Fprintln(w, commentHdr, f.Comment)
- fmt.Fprintln(w, string(f.B64))
- if f.Body != nil {
- w.Write(f.Body)
+ fmt.Fprintln(w, base64.StdEncoding.EncodeToString(f.RawKey))
+ if f.Message != nil {
+ w.Write(f.Message)
}
return nil
}