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:
parent
88da5d44b1
commit
3b2e53c586
3 changed files with 119 additions and 49 deletions
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue