aboutsummaryrefslogtreecommitdiffstats
path: root/key/box.go
diff options
context:
space:
mode:
authorSam Anthony <sam@samanthony.xyz>2025-04-16 16:54:57 -0400
committerSam Anthony <sam@samanthony.xyz>2025-04-16 16:54:57 -0400
commite8e85bb2103d4679a5a0bca8ee175db0c1199b4f (patch)
treec2c2b432441a7ca57edfe22b1e8a0599e26ffeb0 /key/box.go
parent6ef7e52c52b4229e115c3b276123f33a664519bb (diff)
downloadhose-e8e85bb2103d4679a5a0bca8ee175db0c1199b4f.zip
key decoding functions
Diffstat (limited to 'key/box.go')
-rw-r--r--key/box.go15
1 files changed, 9 insertions, 6 deletions
diff --git a/key/box.go b/key/box.go
index 05d8991..38997eb 100644
--- a/key/box.go
+++ b/key/box.go
@@ -60,18 +60,21 @@ func loadBoxKey(filename string) ([32]byte, error) {
}
// Decode key.
+ return decodeBoxKey(buf)
+}
+
+func (bpk1 BoxPublicKey) Compare(bpk2 BoxPublicKey) int {
+ return bytes.Compare(bpk1[:], bpk2[:])
+}
+
+func decodeBoxKey(buf []byte) ([32]byte, error) {
var key [32]byte
if hex.DecodedLen(len(buf)) != len(key) {
- return [32]byte{}, fmt.Errorf("malformed key: expected %d bytes; got %d",
+ return [32]byte{}, fmt.Errorf("malformed box key: expected %d bytes; got %d",
len(key), hex.DecodedLen(len(buf)))
}
if _, err := hex.Decode(key[:], buf); err != nil {
return [32]byte{}, err
}
-
return key, nil
}
-
-func (bpk1 BoxPublicKey) Compare(bpk2 BoxPublicKey) int {
- return bytes.Compare(bpk1[:], bpk2[:])
-}