diff --git a/core/src/trezor/wire/thp_session.py b/core/src/trezor/wire/thp_session.py index c192c2531..db253f757 100644 --- a/core/src/trezor/wire/thp_session.py +++ b/core/src/trezor/wire/thp_session.py @@ -85,7 +85,7 @@ def sync_set_can_send_message(session: SessionThpCache, can_send: bool) -> None: def sync_set_receive_expected_bit(session: SessionThpCache, bit: int) -> None: - if bit != 0 and bit != 1: + if bit not in (0, 1): raise ThpError("Unexpected receive sync bit") # set second bit to "bit" value @@ -126,7 +126,7 @@ def _get_unauthenticated_session_or_none(session_id) -> SessionThpCache | None: def _sync_set_send_bit(session: SessionThpCache, bit: int) -> None: - if bit != 0 and bit != 1: + if bit not in (0, 1): raise ThpError("Unexpected send sync bit") # set third bit to "bit" value diff --git a/core/src/trezor/wire/thp_v1.py b/core/src/trezor/wire/thp_v1.py index facc1e8e9..c053c6a00 100644 --- a/core/src/trezor/wire/thp_v1.py +++ b/core/src/trezor/wire/thp_v1.py @@ -285,7 +285,8 @@ async def _write_report(write, iface: WireInterface, report: bytearray) -> None: async def _handle_broadcast(iface: WireInterface, ctrl_byte, report) -> Message | None: if ctrl_byte != _CHANNEL_ALLOCATION_REQ: raise ThpError("Unexpected ctrl_byte in broadcast channel packet") - length, nonce, checksum = ustruct.unpack(">H8s4s", report[3:]) + nonce, checksum = ustruct.unpack(">8s4s", report[5:]) + # Note that the length field of the channel allocation request is ignored. if not _is_checksum_valid(checksum, data=report[:-4]): raise ThpError("Checksum is not valid")