mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-30 11:28:21 +00:00
src/apps/common: rewrite cache to use getters/setters
This commit is contained in:
parent
6fad2f4283
commit
c1e1e8bf02
@ -1,18 +1,25 @@
|
|||||||
seed = None
|
_seed, _state = None, None
|
||||||
|
|
||||||
|
|
||||||
def get_state():
|
def get_state():
|
||||||
global seed
|
global _state
|
||||||
if seed is None:
|
return _state
|
||||||
return None
|
|
||||||
else:
|
|
||||||
|
def get_seed():
|
||||||
|
global _seed
|
||||||
|
return _seed
|
||||||
|
|
||||||
|
|
||||||
|
def set_seed(seed):
|
||||||
from trezor.crypto import bip32
|
from trezor.crypto import bip32
|
||||||
from trezor.crypto.hashlib import blake2s
|
from trezor.crypto.hashlib import blake2s
|
||||||
node = bip32.from_seed(seed, 'secp256k1')
|
node = bip32.from_seed(seed, 'secp256k1')
|
||||||
state = blake2s(node.public_key()).digest()
|
state = blake2s(node.public_key()).digest()
|
||||||
return state
|
global _seed, _state
|
||||||
|
_seed, _state = seed, state
|
||||||
|
|
||||||
|
|
||||||
def clear():
|
def clear():
|
||||||
global seed
|
global _seed, _state
|
||||||
seed = None
|
_seed, _state = None
|
||||||
|
@ -15,9 +15,10 @@ async def derive_node(ctx: wire.Context, path=[], curve_name=_DEFAULT_CURVE):
|
|||||||
|
|
||||||
async def _get_seed(ctx: wire.Context) -> bytes:
|
async def _get_seed(ctx: wire.Context) -> bytes:
|
||||||
from . import cache
|
from . import cache
|
||||||
if cache.seed is None:
|
if cache.get_seed() is None:
|
||||||
cache.seed = await _compute_seed(ctx)
|
seed = await _compute_seed(ctx)
|
||||||
return cache.seed
|
cache.set_seed(seed)
|
||||||
|
return cache.get_seed()
|
||||||
|
|
||||||
|
|
||||||
async def _compute_seed(ctx: wire.Context) -> bytes:
|
async def _compute_seed(ctx: wire.Context) -> bytes:
|
||||||
|
@ -10,7 +10,7 @@ async def respond_Features(ctx, msg):
|
|||||||
from trezor.messages.Features import Features
|
from trezor.messages.Features import Features
|
||||||
|
|
||||||
if msg.__qualname__ == 'Initialize':
|
if msg.__qualname__ == 'Initialize':
|
||||||
if not hasattr(msg, 'state') or msg.state != cache.get_state():
|
if msg.state is None or msg.state != cache.get_state():
|
||||||
cache.clear()
|
cache.clear()
|
||||||
|
|
||||||
f = Features()
|
f = Features()
|
||||||
|
Loading…
Reference in New Issue
Block a user