forked from mimoo/disco
-
Notifications
You must be signed in to change notification settings - Fork 0
/
asymmetric_test.go
51 lines (42 loc) · 1.06 KB
/
asymmetric_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
package libdisco
import (
"bytes"
"testing"
)
func TestSignVerify(t *testing.T) {
input := []byte("hi, how are you?")
kp, err := GenerateSigningKeypair()
if err != nil {
t.Fatal("failed to generate a signing keypair")
}
sig := kp.Sign(input)
err = kp.Verify(input, sig)
if err != nil {
t.Fatal("failed to verify signature with error : ", err)
}
}
func TestDeterministicSignatures(t *testing.T) {
kp, err := GenerateSigningKeypair()
if err != nil {
t.Fatal("failed to generate a signing keypair")
}
input := []byte("hi, how are you?")
sig1 := kp.Sign(input)
sig2 := kp.Sign(input)
sig1Bytes := sig1.Encode()
sig2Bytes := sig2.Encode()
if !bytes.Equal(sig1Bytes[:], sig2Bytes[:]) {
t.Fatal("signatures are not deterministic doesn't work")
}
}
func BenchmarkSignVerify(b *testing.B) {
kp, err := GenerateSigningKeypair()
if err != nil {
b.Fatal("failed to generate a signing keypair")
}
input := []byte("benchmark how fast do I get signed and it stays consistent")
for n := 0; n < b.N; n++ {
sig := kp.Sign(input)
kp.Verify(input, sig)
}
}