diff --git a/trezor_agent/gpg/decode.py b/trezor_agent/gpg/decode.py index d69050c..ded5c98 100644 --- a/trezor_agent/gpg/decode.py +++ b/trezor_agent/gpg/decode.py @@ -25,10 +25,17 @@ def parse_subpackets(s): while True: try: - subpacket_len = s.readfmt('B') + first = s.readfmt('B') except EOFError: break + if first < 192: + subpacket_len = first + elif first < 255: + subpacket_len = ((first - 192) << 8) + s.readfmt('B') + 192 + else: # first == 255 + subpacket_len = s.readfmt('>L') + subpackets.append(s.read(subpacket_len)) return subpackets