Add preferred symmetric algorithm signature subpacket parsing to PGPPacket
authorW. Trevor King <wking@tremily.us>
Fri, 20 Dec 2013 21:59:57 +0000 (13:59 -0800)
committerW. Trevor King <wking@tremily.us>
Mon, 23 Dec 2013 02:32:14 +0000 (18:32 -0800)
From RFC 4880 [1]:

  (array of one-octet values)

  Symmetric algorithm numbers that indicate which algorithms the key
  holder prefers to use.  The subpacket body is an ordered list of
  octets with the most preferred listed first.  It is assumed that
  only algorithms listed are supported by the recipient's software.
  Algorithm numbers are in Section 9.  This is only found on a self-
  signature.

[1]: http://tools.ietf.org/search/rfc4880#section-5.2.3.7

gpg-migrate.py

index aeda78c2ca155507d7f2346d0369a17e0b4203e6..a1dbb7abb2aea919a34e0d52e1e96a7b1cf5eea5 100755 (executable)
@@ -292,6 +292,11 @@ class PGPPacket (dict):
     def _str_issuer_signature_subpacket(self, subpacket):
         return subpacket['issuer'][-8:].upper()
 
+    def _str_preferred_symmetric_algorithms_signature_subpacket(
+            self, subpacket):
+        return ', '.join(
+            algo for algo in subpacket['preferred-symmetric-algorithms'])
+
     def _str_key_flags_signature_subpacket(self, subpacket):
         return ', '.join(x for x in sorted(subpacket['key-flags']))
 
@@ -551,6 +556,11 @@ class PGPPacket (dict):
     def _parse_issuer_signature_subpacket(self, data, subpacket):
         subpacket['issuer'] = ''.join('{:02x}'.format(byte) for byte in data)
 
+    def _parse_preferred_symmetric_algorithms_signature_subpacket(
+            self, data, subpacket):
+        subpacket['preferred-symmetric-algorithms'] = [
+            self._symmetric_key_algorithms[d] for d in data]
+
     def _parse_key_flags_signature_subpacket(self, data, subpacket):
         subpacket['key-flags'] = set()
         if data[0] & 0x1: