-
Notifications
You must be signed in to change notification settings - Fork 61
/
keys_test.go
126 lines (104 loc) · 2.96 KB
/
keys_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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package lk_test
import (
"crypto/rand"
"github.com/dchest/uniuri"
"github.com/hyperboloide/lk"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Keys", func() {
var k *lk.PrivateKey
BeforeEach(func() {
var err error
k, err = lk.NewPrivateKey()
Ω(err).To(BeNil())
})
It("should test private key bytes", func() {
b, err := k.ToBytes()
Ω(err).To(BeNil())
k1, err := lk.PrivateKeyFromBytes(b)
Ω(err).To(BeNil())
Ω(k1).To(Equal(k))
invalidBytes := make([]byte, 42)
_, err = rand.Read(invalidBytes)
Ω(err).To(BeNil())
k2, err := lk.PrivateKeyFromBytes(invalidBytes)
Ω(err).To(HaveOccurred())
Ω(k2).To(BeNil())
})
It("should test private key b64", func() {
b, err := k.ToB64String()
Ω(err).To(BeNil())
k1, err := lk.PrivateKeyFromB64String(b)
Ω(err).To(BeNil())
Ω(k1).To(Equal(k))
invalidB64Str := uniuri.NewLen(42)
k2, err := lk.PrivateKeyFromB64String(invalidB64Str)
Ω(err).To(HaveOccurred())
Ω(k2).To(BeNil())
})
It("should test private key b32", func() {
b, err := k.ToB32String()
Ω(err).To(BeNil())
k1, err := lk.PrivateKeyFromB32String(b)
Ω(err).To(BeNil())
Ω(k1).To(Equal(k))
invalidB32Str := uniuri.NewLen(42)
k2, err := lk.PrivateKeyFromB32String(invalidB32Str)
Ω(err).To(HaveOccurred())
Ω(k2).To(BeNil())
})
It("should test private key hex", func() {
b, err := k.ToHexString()
Ω(err).To(BeNil())
k1, err := lk.PrivateKeyFromHexString(b)
Ω(err).To(BeNil())
Ω(k1).To(Equal(k))
invalidB32Str := uniuri.NewLen(42)
k2, err := lk.PrivateKeyFromHexString(invalidB32Str)
Ω(err).To(HaveOccurred())
Ω(k2).To(BeNil())
})
It("should test pubic key bytes", func() {
b := k.GetPublicKey().ToBytes()
k1, err := lk.PublicKeyFromBytes(b)
Ω(err).To(BeNil())
Ω(k1).To(Equal(k.GetPublicKey()))
invalidBytes := make([]byte, 42)
_, err = rand.Read(invalidBytes)
Ω(err).To(BeNil())
k2, err := lk.PublicKeyFromBytes(invalidBytes)
Ω(err).To(HaveOccurred())
Ω(k2).To(BeNil())
})
It("should test pubic key b64", func() {
b := k.GetPublicKey().ToB64String()
k1, err := lk.PublicKeyFromB64String(b)
Ω(err).To(BeNil())
Ω(k1).To(Equal(k.GetPublicKey()))
invalidB64Str := uniuri.NewLen(42)
k2, err := lk.PublicKeyFromB64String(invalidB64Str)
Ω(err).To(HaveOccurred())
Ω(k2).To(BeNil())
})
It("should test pubic key b32", func() {
b := k.GetPublicKey().ToB32String()
k1, err := lk.PublicKeyFromB32String(b)
Ω(err).To(BeNil())
Ω(k1).To(Equal(k.GetPublicKey()))
invalidB32Str := uniuri.NewLen(42)
k2, err := lk.PublicKeyFromB32String(invalidB32Str)
Ω(err).To(HaveOccurred())
Ω(k2).To(BeNil())
})
It("should test pubic key hex", func() {
b := k.GetPublicKey().ToHexString()
k1, err := lk.PublicKeyFromHexString(b)
Ω(err).To(BeNil())
Ω(k1).To(Equal(k.GetPublicKey()))
invalidHexStr := uniuri.NewLen(42)
k2, err := lk.PublicKeyFromHexString(invalidHexStr)
Ω(err).To(HaveOccurred())
Ω(k2).To(BeNil())
})
})