-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpgputils_test.go
124 lines (116 loc) · 5 KB
/
pgputils_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
package natscrypto
import (
"fmt"
"io"
"strings"
"testing"
"github.com/stretchr/testify/assert"
"golang.org/x/crypto/openpgp"
)
var (
keyCounter int
lastT *testing.T
lastTKeyCounter int
)
// GetEntity returns an openpgp entity suitable for tests according to a name
// WARNING there is a limited number of keys in the pool and you will
// get a test failure if calling this method in the same test more than the
// number of available keys
// At the moment the number of keys is 4
func GetEntity(t *testing.T) *openpgp.Entity {
if lastT == t {
lastTKeyCounter++
} else {
lastT = t
lastTKeyCounter = 0
}
if lastTKeyCounter >= len(keysList) {
t.Errorf("Not enough keys for this test")
}
entity, err := preparePrivateKey(strings.NewReader(keysList[keyCounter]))
assert.Nil(t, err)
keyCounter++
if keyCounter >= len(keysList) {
keyCounter = 0
}
return entity
}
// PreparePrivateKey prepare a private key in a pgp entity
func preparePrivateKey(secretKeyring io.Reader) (*openpgp.Entity, error) {
entityList, err := openpgp.ReadArmoredKeyRing(secretKeyring)
if err != nil {
err = fmt.Errorf("invalid ascii armor for key: %s", err)
return nil, err
}
for _, entity := range entityList {
// return first key
return entity, nil
}
return nil, fmt.Errorf("no private key found")
}
var keysList = []string{
`-----BEGIN PGP PRIVATE KEY BLOCK-----
Version: GnuPG v1
lQHYBFfjnfEBBACkSVB8eCwoh68tkAi/Ph4N7rFA0sVXZ5elJPTV6Pb8Hhusbp47
ra1LQxGM/xmJ3RkRHxlF7dnTB1N9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