Change ListPackets.key to be backwards compatible.

This also adds a new ``ListPackets.encrypted_to`` list, which contains
all the keyids which a message was encrypted to. ``ListPackets.key`` is
just the first one we discovered that it was encrypted to, for backwards
compatibility.

 * FIXES part of Issue #67.
   https://github.com/isislovecruft/python-gnupg/issues/67

 * CHANGES the additions made in commit f70a7dc4f0 by @tomgalloway in
   PR#70 to be backwards compatible.
   f70a7dc4f0
   https://github.com/isislovecruft/python-gnupg/pull/77
fix/67-hidden-encrypt
Isis Lovecruft 2014-11-27 02:35:52 +00:00
parent 513a48d876
commit 81b2d9d9c2
No known key found for this signature in database
GPG Key ID: 18C16EC5F9F1D673
2 changed files with 11 additions and 5 deletions

View File

@ -1512,8 +1512,12 @@ class ListPackets(object):
self.need_passphrase_sym = None
#: The keyid and uid which this data is encrypted to.
self.userid_hint = None
#: The first key that we detected that a message was encrypted
#: to. This is provided for backwards compatibility. As of Issue #77_,
#: the ``encrypted_to`` attribute should be used instead.
self.key = None
#: A list of keyid's that the message has been encrypted to.
self.key = []
self.encrypted_to = []
def _handle_status(self, key, value):
"""Parse a status code from the attached GnuPG process.
@ -1523,8 +1527,10 @@ class ListPackets(object):
if key == 'NODATA':
self.status = nodata(value)
elif key == 'ENC_TO':
key_to_add, _, _ = value.split()
self.key.append(key_to_add)
key, _, _ = value.split()
if not self.key:
self.key = key
self.encrypted_to.append(key)
elif key == 'NEED_PASSPHRASE':
self.need_passphrase = True
elif key == 'NEED_PASSPHRASE_SYM':

View File

@ -918,7 +918,7 @@ authentication."""
## We expect Alice's key to be hidden (returned as zero's) and Bob's
## key to be there.
expected_values = ["0000000000000000", "E0ED97345F2973D6"]
self.assertEquals(expected_values, self.gpg.list_packets(encrypted).key)
self.assertEquals(expected_values, self.gpg.list_packets(encrypted).encrypted_to)
def test_encryption_throw_keyids(self):
"""Test to ensure throw-keyids=True causes all recipients to be hidden.
@ -957,7 +957,7 @@ boolean circuit causes a considerable overhead."""
## We expect Alice's key to be hidden (returned as zero's) and Bob's
## key to be there.
expected_values = ["0000000000000000", "0000000000000000"]
self.assertEquals(expected_values, self.gpg.list_packets(encrypted).key)
self.assertEquals(expected_values, self.gpg.list_packets(encrypted).encrypted_to)
def test_encryption_decryption_multi_recipient(self):
"""Test decryption of an encrypted string for multiple users"""