-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathkeyec_test.go
104 lines (82 loc) · 1.74 KB
/
keyec_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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package rome_test
import (
"bytes"
"testing"
"github.com/go-compile/rome"
)
func TestParsePublicKey(t *testing.T) {
key, err := generate()
if err != nil {
t.Fatal(err)
}
pub, err := key.Public().Key()
if err != nil {
t.Fatal(err)
}
pub1, err := rome.ParseECPublic(pub)
if err != nil {
t.Fatal(err)
}
x, y := pub1.Points()
x1, y1 := key.Public().Points()
if !bytes.Equal(x.Bytes(), x1.Bytes()) || !bytes.Equal(y.Bytes(), y1.Bytes()) {
t.Fatal("points don't match")
}
}
func TestParseASN1PublicKey(t *testing.T) {
key, err := generate()
if err != nil {
t.Fatal(err)
}
pub, err := key.Public().KeyASN1()
if err != nil {
t.Fatal(err)
}
pub1, err := rome.ParseECPublicASN1(pub)
if err != nil {
t.Fatal(err)
}
x, y := pub1.Points()
x1, y1 := key.Public().Points()
if !bytes.Equal(x.Bytes(), x1.Bytes()) || !bytes.Equal(y.Bytes(), y1.Bytes()) {
t.Fatal("points don't match")
}
}
func TestParsePrivateKey(t *testing.T) {
key, err := generate()
if err != nil {
t.Fatal(err)
}
p, err := key.Private()
if err != nil {
t.Fatal(err)
}
priv, err := rome.ParseECPrivate(p)
if err != nil {
t.Fatal(err)
}
x, y := priv.Public().Points()
x1, y1 := key.Public().Points()
if !bytes.Equal(x.Bytes(), x1.Bytes()) || !bytes.Equal(y.Bytes(), y1.Bytes()) {
t.Fatal("points don't match")
}
}
func TestParseASN1PrivateKey(t *testing.T) {
key, err := generate()
if err != nil {
t.Fatal(err)
}
pub, err := key.PrivateASN1()
if err != nil {
t.Fatal(err)
}
priv, err := rome.ParseECPrivateASN1(pub)
if err != nil {
t.Fatal(err)
}
x, y := priv.Public().Points()
x1, y1 := key.Public().Points()
if !bytes.Equal(x.Bytes(), x1.Bytes()) || !bytes.Equal(y.Bytes(), y1.Bytes()) {
t.Fatal("points don't match")
}
}