1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-16 04:29:08 +00:00

feat(core/sdbackup): pad data for mocked SD card

This commit is contained in:
obrusvit 2024-01-17 10:53:14 +01:00
parent 8415f51a7c
commit 1d8e5068c4
2 changed files with 12 additions and 4 deletions

View File

@ -259,6 +259,7 @@ if __debug__:
from trezor import io from trezor import io
sdcard_switcher = io.sdcard_switcher # local_cache_attribute sdcard_switcher = io.sdcard_switcher # local_cache_attribute
sdcard = io.sdcard # local_cache_attribute
if msg.serial_number is None: if msg.serial_number is None:
sdcard_switcher.eject() sdcard_switcher.eject()
else: else:
@ -267,11 +268,18 @@ if __debug__:
capacity_bytes=msg.capacity_bytes, capacity_bytes=msg.capacity_bytes,
manuf_id=msg.manuf_ID, manuf_id=msg.manuf_ID,
) )
if msg.data_blocks is not None: try:
sdcard = io.sdcard
sdcard.power_on() sdcard.power_on()
for block in msg.data_blocks: for block in msg.data_blocks:
sdcard.write(block.number, block.data) assert len(block.data) <= sdcard.BLOCK_SIZE
block_buffer = utils.empty_bytearray(sdcard.BLOCK_SIZE)
block_buffer.extend(block.data)
padding_len = sdcard.BLOCK_SIZE - len(block_buffer)
block_buffer.extend(b"\x00" * padding_len)
sdcard.write(block.number, block_buffer)
except OSError:
raise wire.ProcessError("SD card operation failed")
finally:
sdcard.power_off() sdcard.power_off()
return Success() return Success()

View File

@ -11,7 +11,7 @@ pytestmark = [pytest.mark.skip_t1, pytest.mark.skip_tr]
def prepare_data_for_sdcard() -> bytes: def prepare_data_for_sdcard() -> bytes:
# MNEMONIC12 backup block # MNEMONIC12 backup block
backup_block_str = "54525A4D000000004C616C636F686F6C20776F6D616E206162757365206D75737420647572696E67206D6F6E69746F72206E6F626C652061637475616C206D6978656420747261646520616E676572206169736C654B1118DAD99C3A21E85AC1CBAE3D41F8BA02BE5E6B8422B3225C9DB53C316D8A0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" backup_block_str = "54525A4D000000004C616C636F686F6C20776F6D616E206162757365206D75737420647572696E67206D6F6E69746F72206E6F626C652061637475616C206D6978656420747261646520616E676572206169736C654B1118DAD99C3A21E85AC1CBAE3D41F8BA02BE5E6B8422B3225C9DB53C316D8A"
return bytes.fromhex(backup_block_str) return bytes.fromhex(backup_block_str)