1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-22 07:28:10 +00:00

modtrezorconfig: don't use mock anymore

This commit is contained in:
Pavol Rusnak 2017-03-30 20:57:46 +02:00
parent 32cf4f36d2
commit 8a6b78187e
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
2 changed files with 2 additions and 53 deletions

View File

@ -1,12 +1,6 @@
import sys from TrezorConfig import Config
if sys.platform == 'trezor':
from .config_mock import Config
_config = Config(None)
else:
from TrezorConfig import Config
_config = Config()
_config = Config()
def get(app: int, key: int) -> bytes: def get(app: int, key: int) -> bytes:
return _config.get(app, key) return _config.get(app, key)

View File

@ -1,45 +0,0 @@
# mock implementation using binary file
import ustruct
class Config:
def __init__(self, filename):
self._data = {}
self._file = filename
self._load()
def _load(self):
if not self._file:
return
try:
with open(self._file, 'rb') as f:
while True:
d = f.read(4)
if len(d) != 4:
break
k, l = ustruct.unpack('<HH', d)
v = f.read(l)
self._data[k] = v
except OSError:
pass
def _save(self):
if not self._file:
return
with open(self._file, 'wb') as f:
for k, v in self._data.items():
f.write(ustruct.pack('<HH', k, len(v)))
f.write(v)
def get(self, app_id, key):
return self._data.get((app_id << 8) | key, bytes())
def set(self, app_id, key, value):
self._data[(app_id << 8) | key] = value
self._save()
def wipe(self):
self._data = {}
self._save()