-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkey_test.go
50 lines (42 loc) · 1.09 KB
/
key_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
package tlstest
import (
"testing"
"github.com/google/go-cmp/cmp"
)
func TestEncDec(t *testing.T) {
text := []byte("The bourgeois human is a virus on the hard drive of the working robot!")
prvKey, err := NewKey()
if err != nil {
t.Errorf("cannot generate private key: %v", err)
return
}
cText, err := Encrypt(text, &prvKey.PublicKey)
if err != nil {
t.Errorf("cannot encrypt text with public key: %v", err)
return
}
res, err := Decrypt(cText, prvKey)
if err != nil {
t.Errorf("cannot encrypt text with public key: %v", err)
return
}
if !cmp.Equal(res, text) {
t.Errorf("\nexpect: %v\ngot : %v\n", text, res)
}
}
func TestDSA(t *testing.T) {
text := []byte("The bourgeois human is a virus on the hard drive of the working robot!")
prvKey, err := NewKey()
if err != nil {
t.Errorf("cannot generate private key: %v", err)
return
}
sig, err := Sign(text, prvKey)
if err != nil {
t.Errorf("cannot sign text with public key: %v", err)
return
}
if err = Verify(text, sig, &prvKey.PublicKey); err != nil {
t.Errorf("text does not match with signature: %v", err)
}
}