1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-01-02 19:40:57 +00:00

feat(core): Implement storage.cache.get_int_all_sessions().

This commit is contained in:
Andrew Kozlik 2023-02-24 13:23:25 +01:00 committed by Martin Milata
parent 0fb55553b7
commit 9bb1d1cf8b
2 changed files with 17 additions and 0 deletions

View File

@ -46,6 +46,12 @@ def get() -> protobuf.MessageType | None:
return protobuf.load_message_buffer(buffer, msg_wire_type)
def is_set_any_session(auth_type: MessageType) -> bool:
return auth_type in storage_cache.get_int_all_sessions(
APP_COMMON_AUTHORIZATION_TYPE
)
def get_wire_types() -> Iterable[int]:
stored_auth_type = storage_cache.get(APP_COMMON_AUTHORIZATION_TYPE)
if stored_auth_type is None:

View File

@ -1,3 +1,4 @@
import builtins
import gc
from micropython import const
from typing import TYPE_CHECKING
@ -273,6 +274,16 @@ def get_int(key: int, default: T | None = None) -> int | T | None: # noqa: F811
return int.from_bytes(encoded, "big")
def get_int_all_sessions(key: int) -> builtins.set[int]:
sessions = [_SESSIONLESS_CACHE] if key & _SESSIONLESS_FLAG else _SESSIONS
values = builtins.set()
for session in sessions:
encoded = session.get(key)
if encoded is not None:
values.add(int.from_bytes(encoded, "big"))
return values
def is_set(key: int) -> bool:
if key & _SESSIONLESS_FLAG:
return _SESSIONLESS_CACHE.is_set(key ^ _SESSIONLESS_FLAG)