From: W. Trevor King Date: Fri, 20 Dec 2013 21:26:48 +0000 (-0800) Subject: Add a signature subpacket parsing/display framework to PGPPacket X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=5b9cef32a956daebf5c4765f76534b2fcad8b665;p=gpg-migrate.git Add a signature subpacket parsing/display framework to PGPPacket Along the lines of the existing packet-parsing framework in PGPPacket.from_bytes. --- diff --git a/gpg-migrate.py b/gpg-migrate.py index 515760b..b5eafaa 100755 --- a/gpg-migrate.py +++ b/gpg-migrate.py @@ -268,7 +268,15 @@ class PGPPacket (dict): if self['unhashed-subpackets']: lines.append(' unhashed subpackets:') for subpacket in self['unhashed-subpackets']: - lines.append(' {}'.format(subpacket['type'])) + method_name = '_str_{}_signature_subpacket'.format( + self._clean_type(type=subpacket['type'])) + method = getattr(self, method_name, None) + if method: + lines.append(' {}: {}'.format( + subpacket['type'], + method(subpacket=subpacket))) + else: + lines.append(' {}'.format(subpacket['type'])) return '\n'.join(lines) def _str_user_id_packet(self): @@ -481,8 +489,16 @@ class PGPPacket (dict): offset += 4 subpacket['type'] = self._signature_subpacket_types[data[offset]] offset += 1 - subpacket['data'] = data[offset: offset + length - 1] - offset += len(subpacket['data']) + subpacket_data = data[offset: offset + length - 1] + offset += len(subpacket_data) + method_name = '_parse_{}_signature_subpacket'.format( + self._clean_type(type=subpacket['type'])) + method = getattr(self, method_name, None) + if not method: + raise NotImplementedError( + 'cannot parse signature subpacket type {!r}'.format( + subpacket['type'])) + method(data=subpacket_data, subpacket=subpacket) return (offset, subpacket) def _parse_signature_packet(self, data):