From be7ee61ddd2a7bafa17d9ed130994089368b53cc Mon Sep 17 00:00:00 2001 From: Jan Pochyla Date: Wed, 23 Nov 2016 14:45:58 +0100 Subject: [PATCH] config: always use bytes() for default value --- extmod/modtrezorconfig/modtrezorconfig.c | 6 +++--- src/trezor/config.py | 10 ++++++---- src/trezor/config_mock.py | 7 ++++--- tests/test_trezor.config.py | 17 ++++++++--------- 4 files changed, 21 insertions(+), 19 deletions(-) diff --git a/extmod/modtrezorconfig/modtrezorconfig.c b/extmod/modtrezorconfig/modtrezorconfig.c index 2519cc8ff..6893ed070 100644 --- a/extmod/modtrezorconfig/modtrezorconfig.c +++ b/extmod/modtrezorconfig/modtrezorconfig.c @@ -32,7 +32,7 @@ STATIC mp_obj_t mod_TrezorConfig_Config_make_new(const mp_obj_type_t *type, size /// def trezor.config.get(app: int, key: int) -> bytes: /// ''' -/// Gets a value of given key for given app (or None if not set). +/// Gets a value of given key for given app (or empty bytes if not set). /// ''' STATIC mp_obj_t mod_TrezorConfig_Config_get(mp_obj_t self, mp_obj_t app, mp_obj_t key) { uint8_t a = mp_obj_get_int(app); @@ -41,8 +41,8 @@ STATIC mp_obj_t mod_TrezorConfig_Config_get(mp_obj_t self, mp_obj_t app, mp_obj_ const void *val; uint32_t len; bool r = norcow_get(appkey, &val, &len); - if (!r) { - return mp_const_none; + if (!r || len == 0) { + return mp_const_empty_bytes; } vstr_t vstr; vstr_init_len(&vstr, len); diff --git a/src/trezor/config.py b/src/trezor/config.py index 1db7ad059..ecb357cef 100644 --- a/src/trezor/config.py +++ b/src/trezor/config.py @@ -6,12 +6,14 @@ else: from TrezorConfig import Config _config = Config() -def get(app, key, default=None): - v = _config.get(app, key) - return v if v else default -def set(app, key, value): +def get(app: int, key: int) -> bytes: + return _config.get(app, key) + + +def set(app: int, key: int, value: bytes): return _config.set(app, key, value) + def wipe(): return _config.wipe() diff --git a/src/trezor/config_mock.py b/src/trezor/config_mock.py index 5db21a1ed..a2f25210b 100644 --- a/src/trezor/config_mock.py +++ b/src/trezor/config_mock.py @@ -2,7 +2,8 @@ import ustruct -def Config(): + +class Config: def __init__(self, filename): self._data = {} @@ -25,8 +26,8 @@ def Config(): f.write(ustruct.pack('