mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-12 00:10:58 +00:00
apps.common: introduce cache module instead of caching in global variables
This commit is contained in:
parent
5e410a3b59
commit
16c7284e98
6
src/apps/common/cache.py
Normal file
6
src/apps/common/cache.py
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
seed = None
|
||||||
|
|
||||||
|
|
||||||
|
def clear():
|
||||||
|
global seed
|
||||||
|
seed = None
|
@ -4,8 +4,6 @@ from trezor.crypto import bip39
|
|||||||
|
|
||||||
_DEFAULT_CURVE = 'secp256k1'
|
_DEFAULT_CURVE = 'secp256k1'
|
||||||
|
|
||||||
_cached_seed = None
|
|
||||||
|
|
||||||
|
|
||||||
async def get_root(session_id: int, curve_name=_DEFAULT_CURVE):
|
async def get_root(session_id: int, curve_name=_DEFAULT_CURVE):
|
||||||
seed = await get_seed(session_id)
|
seed = await get_seed(session_id)
|
||||||
@ -14,10 +12,10 @@ async def get_root(session_id: int, curve_name=_DEFAULT_CURVE):
|
|||||||
|
|
||||||
|
|
||||||
async def get_seed(session_id: int) -> bytes:
|
async def get_seed(session_id: int) -> bytes:
|
||||||
global _cached_seed
|
from . import cache
|
||||||
if _cached_seed is None:
|
if cache.seed is None:
|
||||||
_cached_seed = await compute_seed(session_id)
|
cache.seed = await compute_seed(session_id)
|
||||||
return _cached_seed
|
return cache.seed
|
||||||
|
|
||||||
|
|
||||||
async def compute_seed(session_id: int) -> bytes:
|
async def compute_seed(session_id: int) -> bytes:
|
||||||
|
@ -144,8 +144,10 @@ def load_settings(language: str=None,
|
|||||||
|
|
||||||
|
|
||||||
def wipe():
|
def wipe():
|
||||||
|
from . import cache
|
||||||
lock()
|
lock()
|
||||||
config.wipe()
|
config.wipe()
|
||||||
|
cache.clear()
|
||||||
|
|
||||||
|
|
||||||
def new_device_id() -> str:
|
def new_device_id() -> str:
|
||||||
|
@ -31,7 +31,7 @@ not passing:
|
|||||||
test_msg_changepin.py \
|
test_msg_changepin.py \
|
||||||
test_msg_ethereum_signtx.py
|
test_msg_ethereum_signtx.py
|
||||||
test_msg_getaddress_show.py
|
test_msg_getaddress_show.py
|
||||||
test_msg_loaddevice.py
|
test_msg_loaddevice_xprv.py
|
||||||
test_msg_ping.py
|
test_msg_ping.py
|
||||||
test_msg_resetdevice.py
|
test_msg_resetdevice.py
|
||||||
test_msg_recoverydevice.py
|
test_msg_recoverydevice.py
|
||||||
@ -51,6 +51,7 @@ for i in \
|
|||||||
test_msg_getaddress.py \
|
test_msg_getaddress.py \
|
||||||
test_msg_getentropy.py
|
test_msg_getentropy.py
|
||||||
test_msg_getpublickey.py \
|
test_msg_getpublickey.py \
|
||||||
|
test_msg_loaddevice.py
|
||||||
test_msg_signidentity.py \
|
test_msg_signidentity.py \
|
||||||
test_msg_signmessage.py \
|
test_msg_signmessage.py \
|
||||||
test_msg_signtx.py \
|
test_msg_signtx.py \
|
||||||
|
Loading…
Reference in New Issue
Block a user