refactor(python): inline `ProtocolV2Channel.prepare_channel_without_pairing()`
What changed, and why it matters
This commit is a simple code cleanup: it removes a small helper method and places its contents directly into the function that called it. No behavior changes, no security fixes, and no new risks are visible.
No security action needed; treat as ordinary refactoring.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff inlines prepare_channel_without_pairing() into the ProtocolV2Channel constructor. The same three operations—_reset_sync_bits(), _do_channel_allocation(retries=MAX_RETRANSMISSION_COUNT), and _do_handshake(credential=credential)—are still executed in the same order when prepare_channel_without_pairing=True. The only change is removing the indirection of a private method. There is no change to logic, parameters, error handling, or control flow.
Changed components
python/src/trezorlib/transport/thp/protocol_v2.pyInspect captured patch +4 / −9
diff --git a/python/src/trezorlib/transport/thp/protocol_v2.py b/python/src/trezorlib/transport/thp/protocol_v2.py
index c1c44695..c34a3e34 100644
--- a/python/src/trezorlib/transport/thp/protocol_v2.py
+++ b/python/src/trezorlib/transport/thp/protocol_v2.py
@@ -68,10 +68,11 @@ class ProtocolV2Channel(Channel):
prepare_channel_without_pairing: bool = True,
) -> None:
super().__init__(transport, mapping)
+ self._reset_sync_bits()
if prepare_channel_without_pairing:
- self.trezor_state = self.prepare_channel_without_pairing(
- credential=credential
- )
+ # allow skipping unrelated response packets (e.g. in case of retransmissions)
+ self._do_channel_allocation(retries=MAX_RETRANSMISSION_COUNT)
+ self.trezor_state = self._do_handshake(credential=credential)
def get_channel(self) -> ProtocolV2Channel:
if not self._has_valid_channel:
@@ -127,12 +128,6 @@ class ProtocolV2Channel(Channel):
assert isinstance(msg, message_type)
return msg
- def prepare_channel_without_pairing(self, credential: bytes | None = None) -> int:
- self._reset_sync_bits()
- # allow skipping unrelated response packets (e.g. in case of retransmissions)
- self._do_channel_allocation(retries=MAX_RETRANSMISSION_COUNT)
- return self._do_handshake(credential=credential)
-
def _reset_sync_bits(self) -> None:
self.sync_bit_send = 0
self.sync_bit_receive = 0
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.