aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2016-10-23 16:37:40 +0200
committerDimitri Sokolyuk <demon@dim13.org>2016-10-23 16:37:40 +0200
commit4a38070b2b20f755775b4eaacb142389086e7ac5 (patch)
treefd95e18ee3c4aa8e21961678ee8f089ca5fdfb6a
parentb3c5a8dd24292700e6aafbd10cb14e4291c91df8 (diff)
Read/Write whole struct
-rw-r--r--pub.go14
1 files changed, 5 insertions, 9 deletions
diff --git a/pub.go b/pub.go
index f94faf4..2745c6f 100644
--- a/pub.go
+++ b/pub.go
@@ -3,7 +3,7 @@ package main
import (
"bytes"
"encoding/base64"
- "io"
+ "encoding/binary"
"golang.org/x/crypto/ed25519"
)
@@ -17,18 +17,14 @@ type PubKey struct {
func (v *PubKey) Unmarshal(b []byte) error {
buf := bytes.NewBuffer(b)
dec := base64.NewDecoder(base64.StdEncoding, buf)
- io.ReadFull(dec, v.PKAlg[:])
- io.ReadFull(dec, v.KeyNum[:])
- io.ReadFull(dec, v.PubKey[:])
- return nil
+ err := binary.Read(dec, binary.BigEndian, v)
+ return err
}
func (v *PubKey) Marshal() ([]byte, error) {
buf := new(bytes.Buffer)
enc := base64.NewEncoder(base64.StdEncoding, buf)
- enc.Write(v.PKAlg[:])
- enc.Write(v.KeyNum[:])
- enc.Write(v.PubKey[:])
+ err := binary.Write(enc, binary.BigEndian, v)
enc.Close()
- return buf.Bytes(), nil
+ return buf.Bytes(), err
}