mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-29 10:58:21 +00:00
docs(core): add and modify docs to context and cache
[no changelog]
This commit is contained in:
parent
8c6ed70389
commit
f431265736
@ -16,6 +16,11 @@ SESSION_ID_LENGTH = const(32)
|
|||||||
|
|
||||||
|
|
||||||
class SessionCache(DataCache):
|
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:
|
def __init__(self) -> None:
|
||||||
self.session_id = bytearray(SESSION_ID_LENGTH)
|
self.session_id = bytearray(SESSION_ID_LENGTH)
|
||||||
if utils.BITCOIN_ONLY:
|
if utils.BITCOIN_ONLY:
|
||||||
|
@ -36,6 +36,11 @@ class InvalidSessionError(Exception):
|
|||||||
|
|
||||||
|
|
||||||
class DataCache:
|
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
|
fields: Sequence[int] # field sizes
|
||||||
|
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
@ -110,6 +115,11 @@ class DataCache:
|
|||||||
|
|
||||||
|
|
||||||
class SessionlessCache(DataCache):
|
class SessionlessCache(DataCache):
|
||||||
|
"""
|
||||||
|
A cache for values that are independent of both
|
||||||
|
passphrase seed derivation and the active session.
|
||||||
|
"""
|
||||||
|
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
self.fields = (
|
self.fields = (
|
||||||
64, # APP_COMMON_SEED_WITHOUT_PASSPHRASE
|
64, # APP_COMMON_SEED_WITHOUT_PASSPHRASE
|
||||||
|
@ -16,11 +16,7 @@ if TYPE_CHECKING:
|
|||||||
|
|
||||||
|
|
||||||
class CodecContext(Context):
|
class CodecContext(Context):
|
||||||
"""Wire context.
|
""" "Wire context" for `protocol_v1`."""
|
||||||
|
|
||||||
Represents USB communication inside a particular session on a particular interface
|
|
||||||
(i.e., wire, debug, single BT connection, etc.)
|
|
||||||
"""
|
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
|
@ -53,7 +53,7 @@ WIRE_BUFFER = bytearray(_PROTOBUF_BUFFER_SIZE)
|
|||||||
|
|
||||||
|
|
||||||
async def handle_single_message(ctx: Context, msg: Message) -> bool:
|
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
|
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.
|
a problem is encountered at any point, write the appropriate error on the wire.
|
||||||
|
@ -24,6 +24,13 @@ class Message:
|
|||||||
|
|
||||||
|
|
||||||
class Context:
|
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
|
channel_id: bytes
|
||||||
|
|
||||||
def __init__(self, iface: WireInterface, channel_id: bytes | None = None) -> None:
|
def __init__(self, iface: WireInterface, channel_id: bytes | None = None) -> None:
|
||||||
|
Loading…
Reference in New Issue
Block a user