From: W. Trevor King Date: Thu, 19 Dec 2013 04:37:33 +0000 (-0800) Subject: Track data offset in bytes, and extract the packet payload X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=bb35abab7ef9803674202d95db6c933ec6e1b82c;p=gpg-migrate.git Track data offset in bytes, and extract the packet payload Return the offset when we're done, because there may be multiple packets in a stream. --- diff --git a/gpg-migrate.py b/gpg-migrate.py index f61fb67..905f8b6 100755 --- a/gpg-migrate.py +++ b/gpg-migrate.py @@ -27,6 +27,7 @@ class PGPPacket (dict): def from_bytes(self, data): packet_tag = data[0] + offset = 1 always_one = packet_tag & 1 << 7 if not always_one: raise ValueError('most significant packet tag bit not set') @@ -43,8 +44,12 @@ class PGPPacket (dict): raise NotImplementedError( 'old-format packet of indeterminate length') length_format = '>{}'.format(length_type) - length_data = data[1: 1 + length_bytes] + length_data = data[offset: offset + length_bytes] + offset += length_bytes self['length'] = _struct.unpack(length_format, length_data)[0] + packet = data[offset:offset + self['length']] + offset += self['length'] + return offset def to_bytes(self): pass