1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-22 07:28:10 +00:00

Reformat Python files using black, isort and flake8.

This commit is contained in:
andrew 2019-01-11 20:57:12 +01:00 committed by Pavol Rusnak
parent bddb72d76a
commit e3ab0dfbcb
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
4 changed files with 22 additions and 17 deletions

View File

@ -11,7 +11,9 @@ class PinCancelled(Exception):
@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():
c = dialog.cancel
if matrix.pin:

View File

@ -32,6 +32,7 @@ _AUTOLOCK_DELAY_MS = const(0x0C) # int
_NO_BACKUP = const(0x0D) # bool (0x01 or empty)
# fmt: on
def _set_bool(app: int, key: int, value: bool, public: bool = False) -> None:
if value:
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:
value += _COUNTER_TAIL_LEN * b"\xff"
config.set(app, key, value, public)
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
# 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
# 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
# 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
# 00000021FFFFFFFFFFFFFFFF.
# 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
# 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.
# 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
# bits in the tail are set to zero, the next counter value is stored as
# 00000021FFFFFFFFFFFFFFFF.
value = config.get(app, key, public)
if value is None:
_set_counter(app, key, 0, public)
return 0
head = value[: _COUNTER_HEAD_LEN]
tail = value[_COUNTER_HEAD_LEN :]
head = value[:_COUNTER_HEAD_LEN]
tail = value[_COUNTER_HEAD_LEN:]
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):
_set_counter(app, key, count, public)
return count
@ -78,7 +79,7 @@ def _next_counter(app: int, key: int, public: bool = False) -> int:
zero_count += 1
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)
return count
@ -100,7 +101,7 @@ def is_initialized() -> bool:
def get_label() -> str:
label = config.get(_APP, _LABEL, True) # public
label = config.get(_APP, _LABEL, True) # public
if label is None:
return None
return label.decode()

View File

@ -1,8 +1,8 @@
from trezor import config, log, loop, res, ui
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.request_pin import request_pin
async def bootscreen():

View File

@ -64,7 +64,9 @@ class PinMatrix(ui.Widget):
elif self.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, 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:
# input line with header label
display.text_center(ui.WIDTH // 2, 36, self.label, ui.BOLD, ui.GREY, ui.BG)