Add unit tests for decryption of aead packets
This commit is contained in:
parent
4cea9a0940
commit
373e1ad526
4 changed files with 96 additions and 0 deletions
38
crypto/keyring_message_test.go
Normal file
38
crypto/keyring_message_test.go
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
package crypto
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestAEADKeyRingDecryption(t *testing.T) {
|
||||
pgpMessageData, err := ioutil.ReadFile("testdata/gpg2.3-aead-pgp-message.pgp")
|
||||
if err != nil {
|
||||
t.Fatal("Expected no error when reading message data, got:", err)
|
||||
}
|
||||
pgpMessage := NewPGPMessage(pgpMessageData)
|
||||
|
||||
aeadKey, err := NewKeyFromArmored(readTestFile("gpg2.3-aead-test-key.asc", false))
|
||||
if err != nil {
|
||||
t.Fatal("Expected no error when unarmoring key, got:", err)
|
||||
}
|
||||
|
||||
aeadKeyUnlocked, err := aeadKey.Unlock([]byte("test"))
|
||||
if err != nil {
|
||||
t.Fatal("Expected no error when unlocking, got:", err)
|
||||
}
|
||||
kR, err := NewKeyRing(aeadKeyUnlocked)
|
||||
if err != nil {
|
||||
t.Fatal("Expected no error when creating the keyring, got:", err)
|
||||
}
|
||||
defer kR.ClearPrivateParams()
|
||||
|
||||
decrypted, err := kR.Decrypt(pgpMessage, nil, 0)
|
||||
if err != nil {
|
||||
t.Fatal("Expected no error when decrypting, got:", err)
|
||||
}
|
||||
|
||||
assert.Exactly(t, "hello world\n", decrypted.GetString())
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue