Add binary message helpers (#61)

* Add EncryptBinaryMessageArmored helper function to generate an armored PGP message given binary data and an armored public key

* Add DecryptBinaryMessageArmored helper function to decrypt armored PGP message into binary data

* Streamline the code and fix naming pattern + tests
This commit is contained in:
Jamie 2020-07-17 15:02:39 +08:00 committed by GitHub
parent 88da5d44b1
commit 3b2e53c586
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 119 additions and 49 deletions

View file

@ -130,3 +130,27 @@ func TestAttachmentEncryptionVerification(t *testing.T) {
assert.Exactly(t, attachment, decrypted)
}
func TestArmoredBinaryMessageEncryption(t *testing.T) {
plainData := []byte("Secret message")
armored, err := EncryptBinaryMessageArmored(readTestFile("keyring_publicKey", false), plainData)
if err != nil {
t.Fatal("Expected no error when encrypting, got:", err)
}
assert.Exactly(t, true, crypto.IsPGPMessage(armored))
decrypted, err := DecryptBinaryMessageArmored(
readTestFile("keyring_privateKey", false),
testMailboxPassword, // Password defined in base_test
armored,
)
if err != nil {
t.Fatal("Expected no error when decrypting, got:", err)
}
assert.Exactly(t, plainData, decrypted)
}