From 8c543f61be9b1077441a82e46165cc9ad45f796a Mon Sep 17 00:00:00 2001 From: M1nd3r Date: Wed, 3 Apr 2024 15:33:59 +0200 Subject: [PATCH] refactor(core): remove unnecessary protocol abstraction --- core/src/all_modules.py | 2 -- core/src/trezor/wire/context.py | 6 +++--- core/src/trezor/wire/protocol.py | 21 --------------------- 3 files changed, 3 insertions(+), 26 deletions(-) delete mode 100644 core/src/trezor/wire/protocol.py diff --git a/core/src/all_modules.py b/core/src/all_modules.py index f5b2df94e..3e79ead67 100644 --- a/core/src/all_modules.py +++ b/core/src/all_modules.py @@ -205,8 +205,6 @@ trezor.wire.errors import trezor.wire.errors trezor.wire.message_handler import trezor.wire.message_handler -trezor.wire.protocol -import trezor.wire.protocol trezor.wire.protocol_common import trezor.wire.protocol_common trezor.wire.thp diff --git a/core/src/trezor/wire/context.py b/core/src/trezor/wire/context.py index e18318505..9cc9d4796 100644 --- a/core/src/trezor/wire/context.py +++ b/core/src/trezor/wire/context.py @@ -15,8 +15,8 @@ for ButtonRequests. Of course, `context.wait()` transparently works in such situ from typing import TYPE_CHECKING -import trezor.wire.protocol as protocol from trezor import log, loop, protobuf +from trezor.wire import codec_v1 from .protocol_common import Context, MessageWithId @@ -74,7 +74,7 @@ class CodecContext(Context): def read_from_wire(self) -> Awaitable[MessageWithId]: """Read a whole message from the wire without parsing it.""" - return protocol.read_message(self.iface, self.buffer) + return codec_v1.read_message(self.iface, self.buffer) if TYPE_CHECKING: @@ -176,7 +176,7 @@ class CodecContext(Context): msg_session_id = None if self.channel_id is not None: msg_session_id = bytearray(self.channel_id) - await protocol.write_message( + await codec_v1.write_message( self.iface, MessageWithId( message_type=msg.MESSAGE_WIRE_TYPE, diff --git a/core/src/trezor/wire/protocol.py b/core/src/trezor/wire/protocol.py deleted file mode 100644 index 2894c2863..000000000 --- a/core/src/trezor/wire/protocol.py +++ /dev/null @@ -1,21 +0,0 @@ -from typing import TYPE_CHECKING - -from trezor import utils -from trezor.wire import codec_v1 -from trezor.wire.protocol_common import MessageWithId - -if TYPE_CHECKING: - from trezorio import WireInterface - - -async def read_message(iface: WireInterface, buffer: utils.BufferType) -> MessageWithId: - if utils.USE_THP: - raise Exception("THP protocol should be used instead") - return await codec_v1.read_message(iface, buffer) - - -async def write_message(iface: WireInterface, message: MessageWithId) -> None: - if utils.USE_THP: - raise Exception("THP protocol should be used instead") - await codec_v1.write_message(iface, message.type, message.data) - return