-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathx509_test.go
69 lines (62 loc) · 1.3 KB
/
x509_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
package crypto
import (
"reflect"
"testing"
)
func TestMarshalling(t *testing.T) {
prv, pub, err := GenerateKeyPairP256()
if err != nil {
t.Error(err)
}
derPriv, err := MarhsalPrivateKeyX509(prv)
if err != nil {
t.Error(err)
}
derPub, err := MarshaPublicKeyX509(pub)
if err != nil {
t.Error(err)
}
// now unmarhsal the x509 serilaized keys an verify we have the same
prvKey, err := UnmarshalX509PrivateKey(derPriv)
if err != nil {
t.Error(err)
}
pubKey, err := UnmarshalPublicKeyX509(derPub)
if err != nil {
t.Error(err)
}
if !reflect.DeepEqual(prv, prvKey) {
t.Error("private keys do not match")
}
if !reflect.DeepEqual(pub, pubKey) {
t.Error("public keys do not match")
}
}
func TestDeterministicMarshalling(t *testing.T) {
prv, pub, err := GenerateKeyPairP256()
if err != nil {
t.Error(err)
}
derPriv, err := MarhsalPrivateKeyX509(prv)
if err != nil {
t.Error(err)
}
derPriv2, err := MarhsalPrivateKeyX509(prv)
if err != nil {
t.Error(err)
}
derPub, err := MarshaPublicKeyX509(pub)
if err != nil {
t.Error(err)
}
derPub2, err := MarshaPublicKeyX509(pub)
if err != nil {
t.Error(err)
}
if !reflect.DeepEqual(derPriv, derPriv2) {
t.Error("Marhsalled keys do not match")
}
if !reflect.DeepEqual(derPub, derPub2) {
t.Error("Marshalled keys do not match")
}
}