From bb35abab7ef9803674202d95db6c933ec6e1b82c Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Wed, 18 Dec 2013 20:37:33 -0800 Subject: [PATCH] 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. --- gpg-migrate.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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 -- 2.26.2