From 9c9922e4c24d9452c81e0a2b05d74dc01b6746b1 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Fri, 20 Dec 2013 13:44:39 -0800 Subject: [PATCH] Parse and print the hashed signature subpackets too These packets aren't encrypted, just hashed (i.e. signed). --- gpg-migrate.py | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/gpg-migrate.py b/gpg-migrate.py index cd0a95d..38c7874 100755 --- a/gpg-migrate.py +++ b/gpg-migrate.py @@ -265,20 +265,30 @@ class PGPPacket (dict): def _str_signature_packet(self): lines = [self['signature-type']] + if self['hashed-subpackets']: + lines.append(' hashed subpackets:') + lines.extend(self._str_signature_subpackets( + self['hashed-subpackets'], prefix=' ')) if self['unhashed-subpackets']: lines.append(' unhashed subpackets:') - for subpacket in self['unhashed-subpackets']: - 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'])) + lines.extend(self._str_signature_subpackets( + self['unhashed-subpackets'], prefix=' ')) return '\n'.join(lines) + def _str_signature_subpackets(self, subpackets, prefix): + lines = [] + for subpacket in subpackets: + 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 lines + def _str_issuer_signature_subpacket(self, subpacket): return subpacket['issuer'][-8:].upper() @@ -523,7 +533,8 @@ class PGPPacket (dict): offset += 1 hashed_count = _struct.unpack('>H', data[offset: offset + 2])[0] offset += 2 - self['hashed-subpackets'] = data[offset: offset + hashed_count] + self['hashed-subpackets'] = list(self._parse_signature_subpackets( + data[offset: offset + hashed_count])) offset += hashed_count unhashed_count = _struct.unpack('>H', data[offset: offset + 2])[0] offset += 2 -- 2.26.2