mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-17 20:08:12 +00:00
fix(storage/tests): fix norcow active offset initialization, add missing assert in test_set_locked
[no changelog]
This commit is contained in:
parent
0579ba54fc
commit
f8eae3f023
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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():
|
||||
|
Loading…
Reference in New Issue
Block a user