From: W. Trevor King Date: Sat, 21 Dec 2013 02:12:12 +0000 (-0800) Subject: Add PGPPacket._serialize_string_to_key_specifier X-Git-Url: http://git.tremily.us/?p=gpg-migrate.git;a=commitdiff_plain;h=509056366b8e274398516c4ee366fcb15e6e6dbf 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. --- 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