-
Notifications
You must be signed in to change notification settings - Fork 6
/
gpgeez_test.go
47 lines (36 loc) · 6.11 KB
/
gpgeez_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
package gpgeez
import (
"math/rand"
"testing"
"time"
"github.com/stretchr/testify/assert"
"golang.org/x/crypto/openpgp/packet"
)
type FakeRand struct {
r *rand.Rand
}
func NewFakeRand() *FakeRand {
fakeRand := new(FakeRand)
fakeRand.r = rand.New(rand.NewSource(4))
return fakeRand
}
func (rand FakeRand) Read(p []byte) (n int, err error) {
return rand.r.Read(p)
}
func FakeTime() time.Time {
return time.Unix(1474483116, 0)
}
func TestCreateKey(t *testing.T) {
c := packet.Config{Rand: NewFakeRand(), Time: FakeTime}
config := Config{Config: c, Expiry: 365 * 24 * time.Hour}
key, err := CreateKey("Joe", "test key", "[email protected]", &config)
assert.Nil(t, err, "CreateKey errored")
publicKey, err := key.Armor()
assert.Nil(t, err, "key.Armor() errored")
expectedPublicKey := "-----BEGIN PGP PUBLIC KEY BLOCK-----\n\nxsBNBFfi06wBCADRvTDSCHNi8ylT7H0zr7YrNN6n+4R/AGA8QJeC4rFUzcj2/ovx\nrp0lt1EIayJ9WBD9blScDykQuOiA9Y9LabJZs0bpMSnqKs6xMxKgdzyldos/rDhi\nHkhqo230jJyTf+CcXu+1QxdkAQRtv+mahdNVKsEIC0Aynq/fQho1E3V2ef/daMPK\nX/Pxaut1ndQgv0/XbiTPU8WfCvUGtvnMqJHuCCrBbIf74XqcNQRapcSBNl0ROIBj\naLf2QdrpjabzTdLuLXCiV55Ys9OhZTgFq/VBXZZexzVGRw6FZcCXWZPIenmaqD6A\n/5eLD65gllO3MxwsnwegJBusQDpvOBedDWMNABEBAAHNIEpvZSAodGVzdCBrZXkp\nIDxqb2VAZXhhbXBsZS5jb20+wsB6BBMBCAAuBQJX4tOsCRDwOjjYTA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bded0RTk1TOUNVXnvEqNSIFNu56KqlWcInqu8edPAjSWjXB13trrQfCow083g\n9gbzrbZCJpj8LLz9GtsPsKvCSClREQkzySTXhd8Y0RvmOEdJMmXF\n=2puG\n-----END PGP PUBLIC KEY BLOCK-----"
assert.Equal(t, expectedPublicKey, publicKey)
privateKey, err := key.ArmorPrivate(&config)
assert.Nil(t, err, "key.ArmorPrivate() errored")
expectedPrivateKey := "-----BEGIN PGP PRIVATE KEY BLOCK-----\n\nxcLYBFfi06wBCADRvTDSCHNi8ylT7H0zr7YrNN6n+4R/AGA8QJeC4rFUzcj2/ovx\nrp0lt1EIayJ9WBD9blScDykQuOiA9Y9LabJZs0bpMSnqKs6xMxKgdzyldos/rDhi\nHkhqo230jJyTf+CcXu+1QxdkAQRtv+mahdNVKsEIC0Aynq/fQho1E3V2ef/daMPK\nX/Pxaut1ndQgv0/XbiTPU8WfCvUGtvnMqJHuCCrBbIf74XqcNQRapcSBNl0ROIBj\naLf2QdrpjabzTdLuLXCiV55Ys9OhZTgFq/VBXZZexzVGRw6FZcCXWZPIenmaqD6A\n/5eLD65gllO3MxwsnwegJBusQDpvOBedDWMNABEBAAEAB/wIhb6BGlTN9YF9ZoOj\n4QTu9oQBoWe93V8Ls7g0Wk/IWWBMIQXAuU6rZKqHRAsvuq9eDOilOrx5cHoKG3BK\nKS5VFMLR4OyKFlk1vBSKrq2pL4ry+GWGHyLkKmXiZQBLwgt3byggXmyJ5LywVPcC\nD2QJ9uXHFOXz6JzO3pnABF1mhfW5zgMiwsZ5+o9Mptrh5F+7PeKKHWm5AhjhATnU\ntyiPyKAvS31GYNjR2R/tOCHSlN+TDPmeA7xaOCsuMSkgbZNrF2EJx7/1ZPokuca0\nZdpar2mE0DwQW0P2/MuLhnRR/ufGxfHXNG/KJPu4wKyZTu7SGbCrO1CX/+9ZKqAV\nkmOhBADoNyOON02bhG/qzxyBLc0Rb/h1ov/mYELco7crABu8cz/YlXwynNU9Ynbw\n3+lGKb5EeawxjLYyO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