Add getEntity and getEcryptionKeyIDs functions to key and message types respectively (#55)

* add getEntity function to key struct

* add getEncryptionKeyIDs

* add chengelog + bool return in getEncryptionKeyIDs

* fix description
This commit is contained in:
Ilya Chesnokov 2020-07-02 15:55:11 +07:00 committed by GitHub
parent d1f6f7d718
commit 8d42a53775
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 64 additions and 0 deletions

View file

@ -4,6 +4,7 @@ import (
"bytes"
"encoding/base64"
"testing"
"time"
"github.com/stretchr/testify/assert"
"golang.org/x/crypto/openpgp/packet"
@ -208,6 +209,22 @@ func TestMultipleKeyMessageEncryption(t *testing.T) {
assert.Exactly(t, message.GetString(), decrypted.GetString())
}
func TestMessagegetGetEncryptionKeyIDs(t *testing.T) {
var message = NewPlainMessageFromString("plain text")
assert.Exactly(t, 3, len(keyRingTestMultiple.entities))
ciphertext, err := keyRingTestMultiple.Encrypt(message, keyRingTestPrivate)
if err != nil {
t.Fatal("Expected no error when encrypting, got:", err)
}
ids, ok := ciphertext.getEncryptionKeyIDs()
assert.Exactly(t, 3, len(ids))
assert.True(t, ok)
encKey, ok := keyRingTestMultiple.entities[0].EncryptionKey(time.Now())
assert.True(t, ok)
assert.Exactly(t, encKey.PublicKey.KeyId, ids[0])
}
func TestMessageGetArmoredWithCustomHeaders(t *testing.T) {
var message = NewPlainMessageFromString("plain text")