diff --git a/core/src/apps/thp/pairing.py b/core/src/apps/thp/pairing.py index 2e438f841a..bf2a069a3e 100644 --- a/core/src/apps/thp/pairing.py +++ b/core/src/apps/thp/pairing.py @@ -120,11 +120,7 @@ async def handle_pairing_request( await ctx.show_pairing_method_screen() except UnexpectedMessageException as e: raw_response = e.msg - name = message_handler.get_msg_name(raw_response.type) - if name is None: - req_type = protobuf.type_for_wire(raw_response.type) - else: - req_type = protobuf.type_for_name(name) + req_type = protobuf.type_for_wire(raw_response.type) response = message_handler.wrap_protobuf_load(raw_response.data, req_type) if Cancel.is_type_of(response): diff --git a/core/src/trezor/wire/message_handler.py b/core/src/trezor/wire/message_handler.py index 271a0a649a..8ae6cd05a7 100644 --- a/core/src/trezor/wire/message_handler.py +++ b/core/src/trezor/wire/message_handler.py @@ -51,25 +51,6 @@ def wrap_protobuf_load( raise DataError("Failed to decode message") -if utils.USE_THP: - from trezor.enums import ThpMessageType - - def get_msg_name(msg_type: int) -> str | None: - for name in dir(ThpMessageType): - if not name.startswith("__"): # Skip built-in attributes - value = getattr(ThpMessageType, name) - if isinstance(value, int): - if value == msg_type: - return name - return None - - def get_msg_type(msg_name: str) -> int | None: - value = getattr(ThpMessageType, msg_name) - if isinstance(value, int): - return value - return None - - async def handle_single_message(ctx: Context, msg: Message) -> bool: """Handle a message that was loaded from a WireInterface by the caller. diff --git a/core/src/trezor/wire/thp/memory_manager.py b/core/src/trezor/wire/thp/memory_manager.py index ecfac1e6ff..ef68fb7941 100644 --- a/core/src/trezor/wire/thp/memory_manager.py +++ b/core/src/trezor/wire/thp/memory_manager.py @@ -4,7 +4,6 @@ from micropython import const from storage.cache_thp import SESSION_ID_LENGTH from trezor import protobuf, utils from trezor.wire.errors import WireBufferError -from trezor.wire.message_handler import get_msg_type from . import ThpError from .writer import MAX_PAYLOAD_LEN, MESSAGE_TYPE_LENGTH @@ -149,8 +148,6 @@ def encode_into_buffer( # cannot write message without wire type msg_type = msg.MESSAGE_WIRE_TYPE - if msg_type is None: - msg_type = get_msg_type(msg.MESSAGE_NAME) if msg_type is None: raise Exception("Message has no wire type.") diff --git a/core/src/trezor/wire/thp/pairing_context.py b/core/src/trezor/wire/thp/pairing_context.py index 081a745890..6748daabee 100644 --- a/core/src/trezor/wire/thp/pairing_context.py +++ b/core/src/trezor/wire/thp/pairing_context.py @@ -108,11 +108,8 @@ class PairingContext(Context): raise UnexpectedMessageException(message) if expected_type is None: - name = message_handler.get_msg_name(message.type) - if name is None: - expected_type = protobuf.type_for_wire(message.type) - else: - expected_type = protobuf.type_for_name(name) + expected_type = protobuf.type_for_wire(message.type) + assert expected_type is not None return message_handler.wrap_protobuf_load(message.data, expected_type) @@ -126,11 +123,6 @@ class PairingContext(Context): self, msg: protobuf.MessageType, expected_type: type[protobuf.MessageType] ) -> protobuf.MessageType: expected_wire_type = expected_type.MESSAGE_WIRE_TYPE - if expected_wire_type is None: - expected_wire_type = message_handler.get_msg_type( - expected_type.MESSAGE_NAME - ) - assert expected_wire_type is not None await self.write(msg) @@ -271,11 +263,13 @@ async def handle_message( try: # Find a protobuf.MessageType subclass that describes this # message. Raises if the type is not found. - name = message_handler.get_msg_name(msg.type) - if name is None: - req_type = protobuf.type_for_wire(msg.type) - else: - req_type = protobuf.type_for_name(name) + req_type = protobuf.type_for_wire(msg.type) + + # name = message_handler.get_msg_name(msg.type) + # if name is None: + # req_type = protobuf.type_for_wire(msg.type) + # else: + # req_type = protobuf.type_for_name(name) # Try to decode the message according to schema from # `req_type`. Raises if the message is malformed.