Add PGPPacket.key pointing back up to the PGPKey
authorW. Trevor King <wking@tremily.us>
Sun, 22 Dec 2013 22:02:11 +0000 (14:02 -0800)
committerW. Trevor King <wking@tremily.us>
Mon, 23 Dec 2013 21:41:06 +0000 (13:41 -0800)
This allows us to do stuff like caching passphrases on a key-wide
level, instead of asking for the passphrase for each packet.  The
actuall caching commit is coming next, this commit just lands the
framework.

gpg-migrate.py

index aae79c78f30b72a6da14532e011684390411feed..42905513c9236db2330977908e899e4846259300 100755 (executable)
@@ -271,6 +271,10 @@ class PGPPacket (dict):
 
     _clean_type_regex = _re.compile('\W+')
 
+    def __init__(self, key=None):
+        super(PGPPacket, self).__init__()
+        self.key = key
+
     def _clean_type(self, type=None):
         if type is None:
             type = self['type']
@@ -727,7 +731,7 @@ class PGPPacket (dict):
             subpacket['features'].add('modification detection')
 
     def _parse_embedded_signature_signature_subpacket(self, data, subpacket):
-        subpacket['embedded'] = PGPPacket()
+        subpacket['embedded'] = PGPPacket(key=self.key)
         subpacket['embedded']._parse_signature_packet(data=data)
 
     def _parse_user_id_packet(self, data):
@@ -1016,7 +1020,7 @@ class PGPKey (object):
     def _packets_from_bytes(self, data):
         offset = 0
         while offset < len(data):
-            packet = PGPPacket()
+            packet = PGPPacket(key=self)
             offset += packet.from_bytes(data=data[offset:])
             yield packet