1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-22 07:28:10 +00:00

docs(core): add and modify docs to context and cache

[no changelog]
This commit is contained in:
M1nd3r 2024-11-20 11:16:46 +01:00
parent 8c6ed70389
commit f431265736
5 changed files with 24 additions and 6 deletions

View File

@ -16,6 +16,11 @@ SESSION_ID_LENGTH = const(32)
class SessionCache(DataCache):
"""
A cache for storing values that depend on seed derivation
or are specific to a `protocol_v1` session.
"""
def __init__(self) -> None:
self.session_id = bytearray(SESSION_ID_LENGTH)
if utils.BITCOIN_ONLY:

View File

@ -36,6 +36,11 @@ class InvalidSessionError(Exception):
class DataCache:
"""
A single unit of cache storage, designed to store common-type
values efficiently in bytearrays in a sequential manner.
"""
fields: Sequence[int] # field sizes
def __init__(self) -> None:
@ -110,6 +115,11 @@ class DataCache:
class SessionlessCache(DataCache):
"""
A cache for values that are independent of both
passphrase seed derivation and the active session.
"""
def __init__(self) -> None:
self.fields = (
64, # APP_COMMON_SEED_WITHOUT_PASSPHRASE

View File

@ -16,11 +16,7 @@ if TYPE_CHECKING:
class CodecContext(Context):
"""Wire context.
Represents USB communication inside a particular session on a particular interface
(i.e., wire, debug, single BT connection, etc.)
"""
""" "Wire context" for `protocol_v1`."""
def __init__(
self,

View File

@ -53,7 +53,7 @@ WIRE_BUFFER = bytearray(_PROTOBUF_BUFFER_SIZE)
async def handle_single_message(ctx: Context, msg: Message) -> bool:
"""Handle a message that was loaded from USB by the caller.
"""Handle a message that was loaded from a WireInterface by the caller.
Find the appropriate handler, run it and write its result on the wire. In case
a problem is encountered at any point, write the appropriate error on the wire.

View File

@ -24,6 +24,13 @@ class Message:
class Context:
"""Wire context.
Represents communication between the Trezor device and a host within
a specific session over a particular interface (i.e., wire, debug,
single Bluetooth connection, etc.).
"""
channel_id: bytes
def __init__(self, iface: WireInterface, channel_id: bytes | None = None) -> None: