Parse and print the hashed signature subpackets too
authorW. Trevor King <wking@tremily.us>
Fri, 20 Dec 2013 21:44:39 +0000 (13:44 -0800)
committerW. Trevor King <wking@tremily.us>
Mon, 23 Dec 2013 02:32:13 +0000 (18:32 -0800)
These packets aren't encrypted, just hashed (i.e. signed).

gpg-migrate.py

index cd0a95d60a353fff080593e44f9ede37dc303459..38c7874414c71a3bb613db742fd45cba0d1894ab 100755 (executable)
@@ -265,20 +265,30 @@ class PGPPacket (dict):
 
     def _str_signature_packet(self):
         lines = [self['signature-type']]
+        if self['hashed-subpackets']:
+            lines.append('  hashed subpackets:')
+            lines.extend(self._str_signature_subpackets(
+                self['hashed-subpackets'], prefix='    '))
         if self['unhashed-subpackets']:
             lines.append('  unhashed subpackets:')
-            for subpacket in self['unhashed-subpackets']:
-                method_name = '_str_{}_signature_subpacket'.format(
-                    self._clean_type(type=subpacket['type']))
-                method = getattr(self, method_name, None)
-                if method:
-                    lines.append('    {}: {}'.format(
-                        subpacket['type'],
-                        method(subpacket=subpacket)))
-                else:
-                    lines.append('    {}'.format(subpacket['type']))
+            lines.extend(self._str_signature_subpackets(
+                self['unhashed-subpackets'], prefix='    '))
         return '\n'.join(lines)
 
+    def _str_signature_subpackets(self, subpackets, prefix):
+        lines = []
+        for subpacket in subpackets:
+            method_name = '_str_{}_signature_subpacket'.format(
+                self._clean_type(type=subpacket['type']))
+            method = getattr(self, method_name, None)
+            if method:
+                lines.append('    {}: {}'.format(
+                    subpacket['type'],
+                    method(subpacket=subpacket)))
+            else:
+                lines.append('    {}'.format(subpacket['type']))
+        return lines
+
     def _str_issuer_signature_subpacket(self, subpacket):
         return subpacket['issuer'][-8:].upper()
 
@@ -523,7 +533,8 @@ class PGPPacket (dict):
         offset += 1
         hashed_count = _struct.unpack('>H', data[offset: offset + 2])[0]
         offset += 2
-        self['hashed-subpackets'] = data[offset: offset + hashed_count]
+        self['hashed-subpackets'] = list(self._parse_signature_subpackets(
+            data[offset: offset + hashed_count]))
         offset += hashed_count
         unhashed_count = _struct.unpack('>H', data[offset: offset + 2])[0]
         offset += 2