From: W. Trevor King Date: Sun, 22 Dec 2013 22:00:47 +0000 (-0800) Subject: Make packets_from_bytes a PGPKey method X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=01e6c8f3af5226f34d49be18b9a99f3b97a2ce4c;p=gpg-migrate.git Make packets_from_bytes a PGPKey method There's no need to leave this a stand-alone function if it's only used from PGPKey. --- diff --git a/gpg-migrate.py b/gpg-migrate.py index 04af597..aae79c7 100755 --- a/gpg-migrate.py +++ b/gpg-migrate.py @@ -938,14 +938,6 @@ class PGPPacket (dict): return plaintext -def packets_from_bytes(data): - offset = 0 - while offset < len(data): - packet = PGPPacket() - offset += packet.from_bytes(data=data[offset:]) - yield packet - - class PGPKey (object): """An OpenPGP key with public and private parts. @@ -1007,7 +999,7 @@ class PGPKey (object): key_export = _get_stdout( ['gpg', '--export', self.fingerprint]) self.public_packets = list( - packets_from_bytes(data=key_export)) + self._packets_from_bytes(data=key_export)) if self.public_packets[0]['type'] != 'public-key packet': raise ValueError( '{} does not start with a public-key packet'.format( @@ -1015,12 +1007,19 @@ class PGPKey (object): key_secret_export = _get_stdout( ['gpg', '--export-secret-keys', self.fingerprint]) self.secret_packets = list( - packets_from_bytes(data=key_secret_export)) + self._packets_from_bytes(data=key_secret_export)) if self.secret_packets[0]['type'] != 'secret-key packet': raise ValueError( '{} does not start with a secret-key packet'.format( self.fingerprint)) + def _packets_from_bytes(self, data): + offset = 0 + while offset < len(data): + packet = PGPPacket() + offset += packet.from_bytes(data=data[offset:]) + yield packet + def export_to_gpg(self): raise NotImplemetedError('export to gpg')