Add key-binding targets to PGPPacket._parse_signature_packet
authorW. Trevor King <wking@tremily.us>
Mon, 6 Jan 2014 06:03:57 +0000 (22:03 -0800)
committerW. Trevor King <wking@tremily.us>
Mon, 6 Jan 2014 06:03:57 +0000 (22:03 -0800)
Also adjust the 'user id and public-key packet' targets to always grab
the first packet in the list (public or private) instead of always
looking in the public packets.

This commit assumes that we're loading public packets first, and if a
key has any secret packets, then the current packet is a new secret
packet.

gpg-migrate.py

index 1d139a002936a4e3d62eae66b3b858d03846c309..9ecd9aef929fc4121c1218721edec80738d5b6e9 100755 (executable)
@@ -743,12 +743,21 @@ class PGPPacket (dict):
             o, mpi = self._parse_multiprecision_integer(data=data[offset:])
             offset += o
             self['signature'].append(mpi)
+        if self.key.secret_packets:
+            packets = self.key.secret_packets
+        else:
+            packets = self.key.public_packets
         if self['signature-type'] == 'standalone':
             self['target'] = None
         elif self['signature-type'].endswith(' user id and public-key packet'):
             self['target'] = [
-                [p for p in self.key.public_packets if p['type'] == 'public-key packet'][-1],
-                [p for p in self.key.public_packets if p['type'] == 'user id packet'][-1],
+                packets[0],
+                [p for p in packets if p['type'] == 'user id packet'][-1],
+                ]
+        elif self['signature-type'].endswith('key binding'):
+            self['target'] = [
+                packets[0],
+                [p for p in packets if p['type'] == 'public-subkey packet'][-1],
                 ]
         else:
             raise NotImplementedError(