diff --git a/.gitignore b/.gitignore index 81d26e0..b0b0e3a 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,6 @@ bin dist vendor .vscode -.out -.html +*.out +*.html reports diff --git a/crypto/attachment_test.go b/crypto/attachment_test.go index 219455d..b6ea821 100644 --- a/crypto/attachment_test.go +++ b/crypto/attachment_test.go @@ -13,8 +13,8 @@ import ( func TestAttachmentGetKey(t *testing.T) { testKeyPackets, err := ioutil.ReadFile("testdata/attachment_keypacket") if err != nil { - t.Error("Expected no error while reading from file, got:", err) - return + t.Error("Expected no error while reading from file, got:", err) + return } testKeyPacketsDecoded, err := base64.StdEncoding.DecodeString(string(testKeyPackets)) diff --git a/crypto/key_test.go b/crypto/key_test.go new file mode 100644 index 0000000..18aa4d8 --- /dev/null +++ b/crypto/key_test.go @@ -0,0 +1,38 @@ +package crypto + +import ( + "github.com/stretchr/testify/assert" + // "encoding/base64" + "regexp" + "testing" +) + +const name = "richard.stallman" +const domain = "gnu.org" +const passphrase = "I love GNU" + +var rsaKey, ecKey string + +func TestGenerateRsaKey(t *testing.T) { + var pmCrypto = PmCrypto{} + var err error + rsaKey, err = pmCrypto.generateKey(name, domain, passphrase, "RSA", 1024, nil, nil, nil, nil) + if err != nil { + t.Fatal("Cannot encrypt token:", err) + } + + rTest := regexp.MustCompile("(?s)^-----BEGIN PGP PRIVATE KEY BLOCK-----.*-----END PGP PRIVATE KEY BLOCK-----$") + assert.Regexp(t, rTest, rsaKey) +} + +func TestGenerateECKey(t *testing.T) { + var pmCrypto = PmCrypto{} + var err error + ecKey, err = pmCrypto.generateKey(name, domain, passphrase, "x25519", 1024, nil, nil, nil, nil) + if err != nil { + t.Fatal("Cannot encrypt token:", err) + } + + rTest := regexp.MustCompile("(?s)^-----BEGIN PGP PRIVATE KEY BLOCK-----.*-----END PGP PRIVATE KEY BLOCK-----$") + assert.Regexp(t, rTest, ecKey) +}