1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-18 04:18:10 +00:00

fix(storage/tests): fix norcow active offset initialization, add missing assert in test_set_locked

[no changelog]
This commit is contained in:
tychovrahe 2023-08-21 11:01:00 +02:00 committed by TychoVrahe
parent 0579ba54fc
commit f8eae3f023
3 changed files with 13 additions and 4 deletions

View File

@ -70,7 +70,6 @@ WIPE_CODE_TAG_SIZE = 8
WIPE_CODE_EMPTY = "\0\0\0\0"
# Size of counter. 4B integer and 8B tail.
COUNTER_TAIL = 12
COUNTER_TAIL_SIZE = 8
COUNTER_MAX_TAIL = 64

View File

@ -22,11 +22,21 @@ class Norcow:
for sector in range(consts.NORCOW_SECTOR_COUNT):
if self.sectors[sector][:8] == consts.NORCOW_MAGIC_AND_VERSION:
self.active_sector = sector
self.active_offset = len(consts.NORCOW_MAGIC_AND_VERSION)
self.active_offset = self.find_free_offset()
break
else:
self.wipe()
def find_free_offset(self):
offset = len(consts.NORCOW_MAGIC_AND_VERSION)
while True:
try:
k, v = self._read_item(offset)
except ValueError:
break
offset = offset + self._norcow_item_length(v)
return offset
def wipe(self, sector: int = None):
if sector is None:
sector = self.active_sector

View File

@ -165,8 +165,8 @@ def test_set_locked():
assert common.memory_equals(sc, sp)
for s in (sc, sp):
s.get(0xC001) == b"Ahoj"
s.get(0xC003) == b"test"
assert s.get(0xC001) == b"Ahoj"
assert s.get(0xC003) == b"test"
def test_counter():