From 509056366b8e274398516c4ee366fcb15e6e6dbf Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Fri, 20 Dec 2013 18:12:12 -0800 Subject: [PATCH] Add PGPPacket._serialize_string_to_key_specifier 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 | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/gpg-migrate.py b/gpg-migrate.py index 70c5250..66c19ac 100755 --- a/gpg-migrate.py +++ b/gpg-migrate.py @@ -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 -- 2.26.2