diff --git a/gnupg/_parsers.py b/gnupg/_parsers.py index 852faa4..93da10b 100644 --- a/gnupg/_parsers.py +++ b/gnupg/_parsers.py @@ -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': diff --git a/gnupg/test/test_gnupg.py b/gnupg/test/test_gnupg.py index 06d91b4..49f5ba5 100755 --- a/gnupg/test/test_gnupg.py +++ b/gnupg/test/test_gnupg.py @@ -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"""