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

Delete the U2F counter if it's set to None.

This commit is contained in:
andrew 2019-01-15 18:26:11 +01:00 committed by Pavol Rusnak
parent 92faa9f958
commit 1d43f9bea2
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
2 changed files with 8 additions and 0 deletions

View File

@ -45,6 +45,10 @@ def _get_bool(app: int, key: int, public: bool = False) -> bool:
def _set_counter(app: int, key: int, count: int, public: bool = False) -> None:
if count is None:
config.delete(app, key, public)
return
value = count.to_bytes(_COUNTER_HEAD_LEN, "big")
if public:
value += _COUNTER_TAIL_LEN * b"\xff"

View File

@ -15,6 +15,10 @@ class TestConfig(unittest.TestCase):
storage.set_u2f_counter(350)
for i in range(351, 500):
self.assertEqual(storage.next_u2f_counter(), i)
storage.set_u2f_counter(0)
self.assertEqual(storage.next_u2f_counter(), 1)
storage.set_u2f_counter(None)
self.assertEqual(storage.next_u2f_counter(), 0)
if __name__ == '__main__':