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