mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-10 07:20:56 +00:00
fixup! refactor(core): abstract cache and context [no changelog]
This commit is contained in:
parent
f180c32bb8
commit
91d477c3c4
@ -1,4 +1,4 @@
|
|||||||
from typing import TYPE_CHECKING, Awaitable, Container, overload
|
from typing import TYPE_CHECKING, Awaitable, Container
|
||||||
|
|
||||||
from storage import cache_codec
|
from storage import cache_codec
|
||||||
from storage.cache_common import DataCache, InvalidSessionError
|
from storage.cache_common import DataCache, InvalidSessionError
|
||||||
@ -27,7 +27,6 @@ class CodecContext(Context):
|
|||||||
iface: WireInterface,
|
iface: WireInterface,
|
||||||
buffer: bytearray,
|
buffer: bytearray,
|
||||||
) -> None:
|
) -> None:
|
||||||
self.iface = iface
|
|
||||||
self.buffer = buffer
|
self.buffer = buffer
|
||||||
super().__init__(iface)
|
super().__init__(iface)
|
||||||
|
|
||||||
@ -35,20 +34,6 @@ class CodecContext(Context):
|
|||||||
"""Read a whole message from the wire without parsing it."""
|
"""Read a whole message from the wire without parsing it."""
|
||||||
return codec_v1.read_message(self.iface, self.buffer)
|
return codec_v1.read_message(self.iface, self.buffer)
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
|
||||||
|
|
||||||
@overload
|
|
||||||
async def read(
|
|
||||||
self, expected_types: Container[int]
|
|
||||||
) -> protobuf.MessageType: ...
|
|
||||||
|
|
||||||
@overload
|
|
||||||
async def read(
|
|
||||||
self, expected_types: Container[int], expected_type: type[LoadedMessageType]
|
|
||||||
) -> LoadedMessageType: ...
|
|
||||||
|
|
||||||
reading: bool = False
|
|
||||||
|
|
||||||
async def read(
|
async def read(
|
||||||
self,
|
self,
|
||||||
expected_types: Container[int],
|
expected_types: Container[int],
|
||||||
|
@ -26,7 +26,7 @@ def wrap_protobuf_load(
|
|||||||
expected_type: type[LoadedMessageType],
|
expected_type: type[LoadedMessageType],
|
||||||
) -> LoadedMessageType:
|
) -> LoadedMessageType:
|
||||||
try:
|
try:
|
||||||
if __debug__:
|
if __debug__ and utils.EMULATOR:
|
||||||
log.debug(
|
log.debug(
|
||||||
__name__,
|
__name__,
|
||||||
"Buffer to be parsed to a LoadedMessage: %s",
|
"Buffer to be parsed to a LoadedMessage: %s",
|
||||||
|
@ -22,9 +22,6 @@ class Message:
|
|||||||
self.data = message_data
|
self.data = message_data
|
||||||
self.type = message_type
|
self.type = message_type
|
||||||
|
|
||||||
def to_bytes(self) -> bytes:
|
|
||||||
return self.type.to_bytes(2, "big") + self.data
|
|
||||||
|
|
||||||
|
|
||||||
class Context:
|
class Context:
|
||||||
channel_id: bytes
|
channel_id: bytes
|
||||||
|
Loading…
Reference in New Issue
Block a user