apps.common: introduce cache module instead of caching in global variables

pull/25/head
Pavol Rusnak 7 years ago
parent 5e410a3b59
commit 16c7284e98
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D

@ -0,0 +1,6 @@
seed = None
def clear():
global seed
seed = None

@ -4,8 +4,6 @@ from trezor.crypto import bip39
_DEFAULT_CURVE = 'secp256k1'
_cached_seed = None
async def get_root(session_id: int, curve_name=_DEFAULT_CURVE):
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:
global _cached_seed
if _cached_seed is None:
_cached_seed = await compute_seed(session_id)
return _cached_seed
from . import cache
if cache.seed is None:
cache.seed = await compute_seed(session_id)
return cache.seed
async def compute_seed(session_id: int) -> bytes:

@ -144,8 +144,10 @@ def load_settings(language: str=None,
def wipe():
from . import cache
lock()
config.wipe()
cache.clear()
def new_device_id() -> str:

@ -31,7 +31,7 @@ not passing:
test_msg_changepin.py \
test_msg_ethereum_signtx.py
test_msg_getaddress_show.py
test_msg_loaddevice.py
test_msg_loaddevice_xprv.py
test_msg_ping.py
test_msg_resetdevice.py
test_msg_recoverydevice.py
@ -51,6 +51,7 @@ for i in \
test_msg_getaddress.py \
test_msg_getentropy.py
test_msg_getpublickey.py \
test_msg_loaddevice.py
test_msg_signidentity.py \
test_msg_signmessage.py \
test_msg_signtx.py \

Loading…
Cancel
Save