diff --git a/core/src/apps/common/authorization.py b/core/src/apps/common/authorization.py index 17bc86b53..8b5a8498d 100644 --- a/core/src/apps/common/authorization.py +++ b/core/src/apps/common/authorization.py @@ -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: diff --git a/core/src/storage/cache.py b/core/src/storage/cache.py index aa574358f..7881749d3 100644 --- a/core/src/storage/cache.py +++ b/core/src/storage/cache.py @@ -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)