Add symmetric encryption information to stringified secret key
authorW. Trevor King <wking@tremily.us>
Sat, 21 Dec 2013 19:54:32 +0000 (11:54 -0800)
committerW. Trevor King <wking@tremily.us>
Mon, 23 Dec 2013 21:41:05 +0000 (13:41 -0800)
You can compare this output with 'gpg --list-packets' for sanity.

gpg-migrate.py

index c683a5b7506ac56feec4dfd0c76fc194f9c5a1e7..b5050daede5a8b4d0aee0ce1c64240a34ee21236 100755 (executable)
@@ -298,14 +298,31 @@ class PGPPacket (dict):
     def _str_public_subkey_packet(self):
         return self._str_generic_key_packet()
 
+    def _str_generic_key_packet(self):
+        return self['fingerprint'][-8:].upper()
+
     def _str_secret_key_packet(self):
-        return self._str_generic_key_packet()
+        return self._str_generic_secret_key_packet()
 
     def _str_secret_subkey_packet(self):
-        return self._str_generic_key_packet()
-
-    def _str_generic_key_packet(self):
-        return self['fingerprint'][-8:].upper()
+        return self._str_generic_secret_key_packet()
+
+    def _str_generic_secret_key_packet(self):
+        lines = [self._str_generic_key_packet()]
+        for label, key in [
+                ('symmetric encryption',
+                 'symmetric-encryption-algorithm'),
+                ('s2k hash', 'string-to-key-hash-algorithm'),
+                ('s2k count', 'string-to-key-count'),
+                ('s2k salt', 'string-to-key-salt'),
+                ('IV', 'initial-vector'),
+                ]:
+            if key in self:
+                value = self[key]
+                if isinstance(value, bytes):
+                    value = ' '.join('{:02x}'.format(byte) for byte in value)
+                lines.append('  {}: {}'.format(label, value))
+        return '\n'.join(lines)
 
     def _str_signature_packet(self):
         lines = [self['signature-type']]