From: W. Trevor King Date: Thu, 19 Dec 2013 04:31:15 +0000 (-0800) Subject: Extract the packet length from the old-format length header X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=f52bdcde07fc6171d8fabce07472e8e7149ed1c7;p=gpg-migrate.git Extract the packet length from the old-format length header From RFC 4880 [1]: Scalar numbers are unsigned and are always stored in big-endian format. Using n[k] to refer to the kth octet being interpreted, the value of a two-octet scalar is ((n[0] << 8) + n[1]). The value of a four-octet scalar is ((n[0] << 24) + (n[1] << 16) + (n[2] << 8) + n[3]). The struct big-endian byte-order character is '>' [2]. [1]: http://tools.ietf.org/search/rfc4880#section-3.1 [2]: http://docs.python.org/3/library/struct.html#byte-order-size-and-alignment --- diff --git a/gpg-migrate.py b/gpg-migrate.py index b836926..f61fb67 100755 --- a/gpg-migrate.py +++ b/gpg-migrate.py @@ -42,6 +42,9 @@ class PGPPacket (dict): if not length_bytes: raise NotImplementedError( 'old-format packet of indeterminate length') + length_format = '>{}'.format(length_type) + length_data = data[1: 1 + length_bytes] + self['length'] = _struct.unpack(length_format, length_data)[0] def to_bytes(self): pass