Add PGPPacket._serialize_string_to_key_specifier
authorW. Trevor King <wking@tremily.us>
Sat, 21 Dec 2013 02:12:12 +0000 (18:12 -0800)
committerW. Trevor King <wking@tremily.us>
Mon, 23 Dec 2013 02:32:14 +0000 (18:32 -0800)
This is the inverse of _parse_string_to_key_specifier.  See the
_parse_string_to_key_specifier commits for references to RFC 4880.

gpg-migrate.py

index 70c5250dce1b57330ec92ba285cf6702cd8f9359..66c19acafd6076814056f33780ea6e3a9088c107 100755 (executable)
@@ -703,6 +703,30 @@ class PGPPacket (dict):
             integer = integer >> 8
         return b''.join(chunks)
 
+    def _serialize_string_to_key_specifier(self):
+        string_to_key_type = bytes([
+            self._reverse(
+                self._string_to_key_types, self['string-to-key-type']),
+            ])
+        chunks = [string_to_key_type]
+        if self['string-to-key-type'] == 'simple':
+            chunks.append(bytes([self._reverse(
+                self._hash_algorithms, self['string-to-key-hash-algorithm'])]))
+        elif self['string-to-key-type'] == 'salted':
+            chunks.append(bytes([self._reverse(
+                self._hash_algorithms, self['string-to-key-hash-algorithm'])]))
+            chunks.append(self['string-to-key-salt'])
+        elif self['string-to-key-type'] == 'iterated and salted':
+            chunks.append(bytes([self._reverse(
+                self._hash_algorithms, self['string-to-key-hash-algorithm'])]))
+            chunks.append(self['string-to-key-salt'])
+            chunks.append(bytes([self['string-to-key-coded-count']]))
+        else:
+            raise NotImplementedError(
+                'string-to-key type {}'.format(self['string-to-key-type']))
+        return offset
+        return b''.join(chunks)
+
 
 def packets_from_bytes(data):
     offset = 0