-
Notifications
You must be signed in to change notification settings - Fork 23
/
privatekey_test.go
60 lines (50 loc) · 1.26 KB
/
privatekey_test.go
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
52
53
54
55
56
57
58
59
60
package eciesgo
import (
"crypto/subtle"
"testing"
"github.com/stretchr/testify/assert"
)
const privkeyBase = "f0e5b2c3ba4df3fdb3ecea30d0e60c4e4a31d1ba928f51783ae18bbd3cada572"
var privkeys = []string{
"73d808dc0da21075f252937986a78c84f1c2abbd4649d597f9473e14209efc90",
"19848cb43883723309ace215ba1cbe80907f6e3faeaab32c68034d5f521a57de",
}
func TestNewPrivateKeyFromHex(t *testing.T) {
_, err := NewPrivateKeyFromHex(testingReceiverPrivkeyHex)
assert.NoError(t, err)
}
func TestPrivateKey_Hex(t *testing.T) {
privkey, err := GenerateKey()
if !assert.NoError(t, err) {
return
}
privkey.Hex()
}
func TestPrivateKey_Equals(t *testing.T) {
privkey, err := GenerateKey()
if !assert.NoError(t, err) {
return
}
assert.True(t, privkey.Equals(privkey))
}
func TestPrivateKey_UnsafeECDH(t *testing.T) {
privkey1, err := NewPrivateKeyFromHex(privkeyBase)
if !assert.NoError(t, err) {
return
}
for _, key := range privkeys {
privkey2, err := NewPrivateKeyFromHex(key)
if !assert.NoError(t, err) {
return
}
ss1, err := privkey1.ECDH(privkey2.PublicKey)
if !assert.NoError(t, err) {
return
}
ss2, err := privkey2.ECDH(privkey1.PublicKey)
if !assert.NoError(t, err) {
return
}
assert.Equal(t, subtle.ConstantTimeCompare(ss1, ss2), 1)
}
}