1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-02-07 05:02:38 +00:00
trezor-firmware/core/src/storage/cache.py

42 lines
977 B
Python
Raw Normal View History

from trezor.crypto import random
2018-07-03 14:20:26 +00:00
2019-07-03 13:07:04 +00:00
if False:
from typing import Optional
2019-07-03 13:07:04 +00:00
_cached_seed = None # type: Optional[bytes]
_cached_seed_without_passphrase = None # type: Optional[bytes] # Needed for SLIP-21
_cached_session_id = None # type: Optional[bytes]
2019-07-03 13:07:04 +00:00
2019-11-23 18:12:57 +00:00
def get_session_id() -> bytes:
global _cached_session_id
if not _cached_session_id:
_cached_session_id = random.bytes(32)
return _cached_session_id
def set_seed(seed: Optional[bytes]) -> None:
global _cached_seed
_cached_seed = seed
2019-07-03 13:07:04 +00:00
def get_seed() -> Optional[bytes]:
return _cached_seed
def set_seed_without_passphrase(seed: Optional[bytes]) -> None:
global _cached_seed_without_passphrase
_cached_seed_without_passphrase = seed
def get_seed_without_passphrase() -> Optional[bytes]:
return _cached_seed_without_passphrase
def clear() -> None:
global _cached_session_id
_cached_session_id = None
set_seed(None)
set_seed_without_passphrase(None)