You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
trezor-firmware/core/src/apps/common/storage/__init__.py

36 lines
1017 B

from trezor import config
from apps.common import cache
from apps.common.storage import common, device
def set_current_version() -> None:
device.set_version(common._STORAGE_VERSION_CURRENT)
def is_initialized() -> bool:
return device.is_version_stored()
def wipe() -> None:
config.wipe()
cache.clear()
def init_unlocked() -> None:
# Check for storage version upgrade.
version = device.get_version()
if version == common._STORAGE_VERSION_01:
_migrate_from_version_01()
def _migrate_from_version_01() -> None:
# Make the U2F counter public and writable even when storage is locked.
# U2F counter wasn't public, so we are intentionally not using storage.device module.
counter = common._get(common._APP_DEVICE, device.U2F_COUNTER)
if counter is not None:
device.set_u2f_counter(int.from_bytes(counter, "big"))
# Delete the old, non-public U2F_COUNTER.
common._delete(common._APP_DEVICE, device.U2F_COUNTER)
set_current_version()