mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-05-29 04:08:46 +00:00
Reformat Python files using black, isort and flake8.
This commit is contained in:
parent
bddb72d76a
commit
e3ab0dfbcb
@ -11,7 +11,9 @@ class PinCancelled(Exception):
|
|||||||
|
|
||||||
|
|
||||||
@ui.layout
|
@ui.layout
|
||||||
async def request_pin(label=None, attempts_remaining=None, cancellable: bool = True) -> str:
|
async def request_pin(
|
||||||
|
label=None, attempts_remaining=None, cancellable: bool = True
|
||||||
|
) -> str:
|
||||||
def onchange():
|
def onchange():
|
||||||
c = dialog.cancel
|
c = dialog.cancel
|
||||||
if matrix.pin:
|
if matrix.pin:
|
||||||
|
@ -32,6 +32,7 @@ _AUTOLOCK_DELAY_MS = const(0x0C) # int
|
|||||||
_NO_BACKUP = const(0x0D) # bool (0x01 or empty)
|
_NO_BACKUP = const(0x0D) # bool (0x01 or empty)
|
||||||
# fmt: on
|
# fmt: on
|
||||||
|
|
||||||
|
|
||||||
def _set_bool(app: int, key: int, value: bool, public: bool = False) -> None:
|
def _set_bool(app: int, key: int, value: bool, public: bool = False) -> None:
|
||||||
if value:
|
if value:
|
||||||
config.set(app, key, _TRUE_BYTE, public)
|
config.set(app, key, _TRUE_BYTE, public)
|
||||||
@ -48,27 +49,27 @@ def _set_counter(app: int, key: int, count: int, public: bool = False) -> None:
|
|||||||
if public:
|
if public:
|
||||||
value += _COUNTER_TAIL_LEN * b"\xff"
|
value += _COUNTER_TAIL_LEN * b"\xff"
|
||||||
config.set(app, key, value, public)
|
config.set(app, key, value, public)
|
||||||
|
|
||||||
|
|
||||||
def _next_counter(app: int, key: int, public: bool = False) -> int:
|
def _next_counter(app: int, key: int, public: bool = False) -> int:
|
||||||
# If the counter value is public, then it is stored as a four byte integer in
|
# If the counter value is public, then it is stored as a four byte integer in
|
||||||
# big endian byte order, called the "head", followed an eight byte "tail". The
|
# big endian byte order, called the "head", followed an eight byte "tail". The
|
||||||
# counter value is equal to the integer value of the head plus the number of
|
# counter value is equal to the integer value of the head plus the number of
|
||||||
# zero bits in the tail. The counter value 0 is stored as 00000000FFFFFFFFFFFFFFFF.
|
# zero bits in the tail. The counter value 0 is stored as 00000000FFFFFFFFFFFFFFFF.
|
||||||
# With each increment the tail is shifted to the right by one bit. Thus after
|
# With each increment the tail is shifted to the right by one bit. Thus after
|
||||||
# three increments the stored value is 000000001FFFFFFFFFFFFFFF. Once all the
|
# three increments the stored value is 000000001FFFFFFFFFFFFFFF. Once all the
|
||||||
# bits in the tail are set to zero, the next counter value is stored as
|
# bits in the tail are set to zero, the next counter value is stored as
|
||||||
# 00000021FFFFFFFFFFFFFFFF.
|
# 00000021FFFFFFFFFFFFFFFF.
|
||||||
|
|
||||||
value = config.get(app, key, public)
|
value = config.get(app, key, public)
|
||||||
if value is None:
|
if value is None:
|
||||||
_set_counter(app, key, 0, public)
|
_set_counter(app, key, 0, public)
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
head = value[: _COUNTER_HEAD_LEN]
|
head = value[:_COUNTER_HEAD_LEN]
|
||||||
tail = value[_COUNTER_HEAD_LEN :]
|
tail = value[_COUNTER_HEAD_LEN:]
|
||||||
i = tail.rfind(b"\x00") + 1
|
i = tail.rfind(b"\x00") + 1
|
||||||
count = int.from_bytes(head, "big") + 1 + 8*i
|
count = int.from_bytes(head, "big") + 1 + 8 * i
|
||||||
if i == len(tail):
|
if i == len(tail):
|
||||||
_set_counter(app, key, count, public)
|
_set_counter(app, key, count, public)
|
||||||
return count
|
return count
|
||||||
@ -78,7 +79,7 @@ def _next_counter(app: int, key: int, public: bool = False) -> int:
|
|||||||
zero_count += 1
|
zero_count += 1
|
||||||
count += zero_count
|
count += zero_count
|
||||||
|
|
||||||
tail = tail[:i] + bytes([tail[i] >> 1]) + tail[i+1:]
|
tail = tail[:i] + bytes([tail[i] >> 1]) + tail[i + 1 :]
|
||||||
config.set(app, key, head + tail, public)
|
config.set(app, key, head + tail, public)
|
||||||
return count
|
return count
|
||||||
|
|
||||||
@ -100,7 +101,7 @@ def is_initialized() -> bool:
|
|||||||
|
|
||||||
|
|
||||||
def get_label() -> str:
|
def get_label() -> str:
|
||||||
label = config.get(_APP, _LABEL, True) # public
|
label = config.get(_APP, _LABEL, True) # public
|
||||||
if label is None:
|
if label is None:
|
||||||
return None
|
return None
|
||||||
return label.decode()
|
return label.decode()
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
from trezor import config, log, loop, res, ui
|
from trezor import config, log, loop, res, ui
|
||||||
from trezor.pin import pin_to_int, show_pin_timeout
|
from trezor.pin import pin_to_int, show_pin_timeout
|
||||||
|
|
||||||
from apps.common.request_pin import request_pin
|
|
||||||
from apps.common import storage
|
from apps.common import storage
|
||||||
|
from apps.common.request_pin import request_pin
|
||||||
|
|
||||||
|
|
||||||
async def bootscreen():
|
async def bootscreen():
|
||||||
|
@ -64,7 +64,9 @@ class PinMatrix(ui.Widget):
|
|||||||
elif self.sublabel:
|
elif self.sublabel:
|
||||||
# input line with header label and sublabel
|
# input line with header label and sublabel
|
||||||
display.text_center(ui.WIDTH // 2, 20, self.label, ui.BOLD, ui.GREY, ui.BG)
|
display.text_center(ui.WIDTH // 2, 20, self.label, ui.BOLD, ui.GREY, ui.BG)
|
||||||
display.text_center(ui.WIDTH // 2, 46, self.sublabel, ui.NORMAL, ui.GREY, ui.BG)
|
display.text_center(
|
||||||
|
ui.WIDTH // 2, 46, self.sublabel, ui.NORMAL, ui.GREY, ui.BG
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
# input line with header label
|
# input line with header label
|
||||||
display.text_center(ui.WIDTH // 2, 36, self.label, ui.BOLD, ui.GREY, ui.BG)
|
display.text_center(ui.WIDTH // 2, 36, self.label, ui.BOLD, ui.GREY, ui.BG)
|
||||||
|
Loading…
Reference in New Issue
Block a user