blob: d13bdd64ab281ddfd27c57e5b647a776b558cc4e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
package main
import (
"encoding/hex"
"errors"
)
const (
NoisePublicKeySize = 32
NoisePrivateKeySize = 32
NoiseSymmetricKeySize = 32
)
type (
NoisePublicKey [NoisePublicKeySize]byte
NoisePrivateKey [NoisePrivateKeySize]byte
NoiseSymmetricKey [NoiseSymmetricKeySize]byte
NoiseNonce uint64 // padded to 12-bytes
)
func (key *NoisePrivateKey) FromHex(s string) error {
slice, err := hex.DecodeString(s)
if err != nil {
return err
}
if len(slice) != NoisePrivateKeySize {
return errors.New("Invalid length of hex string for curve25519 point")
}
copy(key[:], slice)
return nil
}
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) ToHex() string {
return hex.EncodeToString(key[:])
}
|