From 9550c5f054820de258ddafebb9397aea9b42411b Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Mon, 23 Dec 2013 08:58:21 -0800 Subject: [PATCH] Adjust PGPKey._packets_from_bytes to append on the fly With the list(iterator) approach, signature packets in the stream did not have access to already-parsed packets for target extraction. Now they do. --- gpg-migrate.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/gpg-migrate.py b/gpg-migrate.py index f5a757c..0a7d116 100755 --- a/gpg-migrate.py +++ b/gpg-migrate.py @@ -1095,16 +1095,16 @@ class PGPKey (object): def import_from_gpg(self): key_export = _get_stdout( ['gpg', '--export', self.fingerprint]) - self.public_packets = list( - self._packets_from_bytes(data=key_export)) + self.public_packets = [] + self._packets_from_bytes(list=self.public_packets, data=key_export) if self.public_packets[0]['type'] != 'public-key packet': raise ValueError( '{} does not start with a public-key packet'.format( self.fingerprint)) key_secret_export = _get_stdout( ['gpg', '--export-secret-keys', self.fingerprint]) - self.secret_packets = list( - self._packets_from_bytes(data=key_secret_export)) + self.secret_packets = [] + self._packets_from_bytes(list=self.secret_packets, data=key_secret_export) if self.secret_packets[0]['type'] != 'secret-key packet': raise ValueError( '{} does not start with a secret-key packet'.format( @@ -1112,12 +1112,12 @@ class PGPKey (object): for packet in self.public_packets + self.secret_packets: packet.check_roundtrip() - def _packets_from_bytes(self, data): + def _packets_from_bytes(self, list, data): offset = 0 while offset < len(data): packet = PGPPacket(key=self) offset += packet.from_bytes(data=data[offset:]) - yield packet + list.append(packet) def export_to_gpg(self): raise NotImplemetedError('export to gpg') -- 2.26.2