aboutsummaryrefslogtreecommitdiffstats
path: root/src/noise.go
diff options
context:
space:
mode:
authorMathias Hall-Andersen <mathias@hall-andersen.dk>2017-06-01 21:31:30 +0200
committerMathias Hall-Andersen <mathias@hall-andersen.dk>2017-06-01 21:31:30 +0200
commitec3d656bebb9ee7c38724500779b7ad322ba0377 (patch)
tree766c47aa8bcd69e6d6db1383dfdf62fc861723c1 /src/noise.go
parentMerge branch 'master' of git.zx2c4.com:wireguard-go (diff)
downloadwireguard-go-ec3d656bebb9ee7c38724500779b7ad322ba0377.tar.xz
wireguard-go-ec3d656bebb9ee7c38724500779b7ad322ba0377.zip
Inital implementation of trie
Diffstat (limited to 'src/noise.go')
-rw-r--r--src/noise.go38
1 files changed, 21 insertions, 17 deletions
diff --git a/src/noise.go b/src/noise.go
index d13bdd6..5508f9a 100644
--- a/src/noise.go
+++ b/src/noise.go
@@ -18,34 +18,38 @@ type (
NoiseNonce uint64 // padded to 12-bytes
)
-func (key *NoisePrivateKey) FromHex(s string) error {
- slice, err := hex.DecodeString(s)
+func loadExactHex(dst []byte, src string) error {
+ slice, err := hex.DecodeString(src)
if err != nil {
return err
}
- if len(slice) != NoisePrivateKeySize {
- return errors.New("Invalid length of hex string for curve25519 point")
+ if len(slice) != len(dst) {
+ return errors.New("Hex string does not fit the slice")
}
- copy(key[:], slice)
+ copy(dst, slice)
return nil
}
-func (key *NoisePrivateKey) ToHex() string {
+func (key *NoisePrivateKey) FromHex(src string) error {
+ return loadExactHex(key[:], src)
+}
+
+func (key NoisePrivateKey) ToHex() string {
return hex.EncodeToString(key[:])
}
-func (key *NoisePublicKey) FromHex(s string) error {
- slice, err := hex.DecodeString(s)
- if err != nil {
- return err
- }
- if len(slice) != NoisePublicKeySize {
- return errors.New("Invalid length of hex string for curve25519 scalar")
- }
- copy(key[:], slice)
- return nil
+func (key *NoisePublicKey) FromHex(src string) error {
+ return loadExactHex(key[:], src)
+}
+
+func (key NoisePublicKey) ToHex() string {
+ return hex.EncodeToString(key[:])
+}
+
+func (key *NoiseSymmetricKey) FromHex(src string) error {
+ return loadExactHex(key[:], src)
}
-func (key *NoisePublicKey) ToHex() string {
+func (key NoiseSymmetricKey) ToHex() string {
return hex.EncodeToString(key[:])
}