mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-25 07:48:10 +00:00
core: Fix mypy warnings in FatFS and SD salt code.
This commit is contained in:
parent
5401f88d52
commit
c25a41aa57
@ -125,7 +125,17 @@ typedef struct _mp_obj_FatFSFile_t {
|
||||
FIL fp;
|
||||
} 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
|
||||
/// """
|
||||
@ -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,
|
||||
mod_trezorio_FatFSFile_read);
|
||||
|
||||
/// def write(self, data: bytearray) -> int:
|
||||
/// def write(self, data: Union[bytes, bytearray]) -> int:
|
||||
/// """
|
||||
/// Write data to the file
|
||||
/// """
|
||||
|
@ -7,7 +7,17 @@ class FatFSFile:
|
||||
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
|
||||
"""
|
||||
@ -22,7 +32,7 @@ class FatFSFile:
|
||||
Read data from the file
|
||||
"""
|
||||
|
||||
def write(self, data: bytearray) -> int:
|
||||
def write(self, data: Union[bytes, bytearray]) -> int:
|
||||
"""
|
||||
Write data to the file
|
||||
"""
|
||||
|
@ -45,11 +45,11 @@ async def _insert_card_dialog(ctx: Optional[wire.Context]) -> None:
|
||||
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()
|
||||
|
||||
|
||||
def _get_salt_path(new: bool = False) -> bytes:
|
||||
def _get_salt_path(new: bool = False) -> str:
|
||||
if new:
|
||||
return "%s/salt.new" % _get_device_dir()
|
||||
else:
|
||||
@ -72,9 +72,10 @@ async def request_sd_salt(
|
||||
fs.mount()
|
||||
|
||||
# Load salt if it exists.
|
||||
salt = None # type: Optional[bytearray]
|
||||
try:
|
||||
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)
|
||||
f.read(salt)
|
||||
f.read(salt_tag)
|
||||
@ -88,9 +89,10 @@ async def request_sd_salt(
|
||||
return salt
|
||||
|
||||
# Load salt.new if it exists.
|
||||
new_salt = None # type: Optional[bytearray]
|
||||
try:
|
||||
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)
|
||||
f.read(new_salt)
|
||||
f.read(new_salt_tag)
|
||||
|
Loading…
Reference in New Issue
Block a user