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

core: Fix mypy warnings in FatFS and SD salt code.

This commit is contained in:
Andrew Kozlik 2019-10-09 17:07:25 +02:00
parent 5401f88d52
commit c25a41aa57
3 changed files with 30 additions and 8 deletions

View File

@ -125,7 +125,17 @@ typedef struct _mp_obj_FatFSFile_t {
FIL fp; FIL fp;
} mp_obj_FatFSFile_t; } mp_obj_FatFSFile_t;
/// def __exit__(self) -> None: /// def __enter__(self) -> FatFSFile:
/// """
/// Return an open file object
/// """
/// from types import TracebackType
/// def __exit__(
/// self, type: Optional[Type[BaseException]],
/// value: Optional[BaseException],
/// traceback: Optional[TracebackType],
/// ) -> None:
/// """ /// """
/// Close an open file object /// Close an open file object
/// """ /// """
@ -175,7 +185,7 @@ STATIC mp_obj_t mod_trezorio_FatFSFile_read(mp_obj_t self, mp_obj_t data) {
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorio_FatFSFile_read_obj, STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorio_FatFSFile_read_obj,
mod_trezorio_FatFSFile_read); mod_trezorio_FatFSFile_read);
/// def write(self, data: bytearray) -> int: /// def write(self, data: Union[bytes, bytearray]) -> int:
/// """ /// """
/// Write data to the file /// Write data to the file
/// """ /// """

View File

@ -7,7 +7,17 @@ class FatFSFile:
Class encapsulating file Class encapsulating file
""" """
def __exit__(self) -> None: def __enter__(self) -> FatFSFile:
"""
Return an open file object
"""
from types import TracebackType
def __exit__(
self, type: Optional[Type[BaseException]],
value: Optional[BaseException],
traceback: Optional[TracebackType],
) -> None:
""" """
Close an open file object Close an open file object
""" """
@ -22,7 +32,7 @@ class FatFSFile:
Read data from the file Read data from the file
""" """
def write(self, data: bytearray) -> int: def write(self, data: Union[bytes, bytearray]) -> int:
""" """
Write data to the file Write data to the file
""" """

View File

@ -45,11 +45,11 @@ async def _insert_card_dialog(ctx: Optional[wire.Context]) -> None:
await require_confirm(ctx, text, confirm=None, cancel="Close") await require_confirm(ctx, text, confirm=None, cancel="Close")
def _get_device_dir() -> bytes: def _get_device_dir() -> str:
return "/trezor/device_%s" % storage.device.get_device_id().lower() return "/trezor/device_%s" % storage.device.get_device_id().lower()
def _get_salt_path(new: bool = False) -> bytes: def _get_salt_path(new: bool = False) -> str:
if new: if new:
return "%s/salt.new" % _get_device_dir() return "%s/salt.new" % _get_device_dir()
else: else:
@ -72,9 +72,10 @@ async def request_sd_salt(
fs.mount() fs.mount()
# Load salt if it exists. # Load salt if it exists.
salt = None # type: Optional[bytearray]
try: try:
with fs.open(salt_path, "r") as f: with fs.open(salt_path, "r") as f:
salt = bytearray(SD_SALT_LEN_BYTES) # type: Optional[bytearray] salt = bytearray(SD_SALT_LEN_BYTES)
salt_tag = bytearray(SD_SALT_AUTH_TAG_LEN_BYTES) salt_tag = bytearray(SD_SALT_AUTH_TAG_LEN_BYTES)
f.read(salt) f.read(salt)
f.read(salt_tag) f.read(salt_tag)
@ -88,9 +89,10 @@ async def request_sd_salt(
return salt return salt
# Load salt.new if it exists. # Load salt.new if it exists.
new_salt = None # type: Optional[bytearray]
try: try:
with fs.open(new_salt_path, "r") as f: with fs.open(new_salt_path, "r") as f:
new_salt = bytearray(SD_SALT_LEN_BYTES) # type: Optional[bytearray] new_salt = bytearray(SD_SALT_LEN_BYTES)
new_salt_tag = bytearray(SD_SALT_AUTH_TAG_LEN_BYTES) new_salt_tag = bytearray(SD_SALT_AUTH_TAG_LEN_BYTES)
f.read(new_salt) f.read(new_salt)
f.read(new_salt_tag) f.read(new_salt_tag)