mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-26 16:18:22 +00:00
code style
This commit is contained in:
parent
6e15b37205
commit
98e82e3cd5
@ -11,9 +11,9 @@ def nth(n):
|
||||
|
||||
|
||||
@unimport
|
||||
async def layout_recovery_device(session_id, message):
|
||||
async def layout_recovery_device(session_id, msg):
|
||||
|
||||
msg = 'Please enter ' + nth(message.word_count) + ' word'
|
||||
msg = 'Please enter ' + nth(msg.word_count) + ' word'
|
||||
|
||||
ui.display.clear()
|
||||
ui.header('Recovery device', ui.ICON_RECOVERY, ui.BLACK, ui.LIGHT_GREEN)
|
||||
|
@ -42,7 +42,9 @@ __names_obj = [
|
||||
'Text',
|
||||
]
|
||||
|
||||
|
||||
class __dummy:
|
||||
|
||||
def __getitem__(self, *args):
|
||||
return object
|
||||
|
||||
@ -54,9 +56,11 @@ for __n in __names_get:
|
||||
for __n in __names_obj:
|
||||
globals()[__n] = object
|
||||
|
||||
|
||||
def TypeVar(*args):
|
||||
return object
|
||||
|
||||
|
||||
def NewType(*args):
|
||||
return lambda x: x
|
||||
|
||||
|
@ -1,59 +1,69 @@
|
||||
from TrezorCrypto import AES
|
||||
|
||||
|
||||
def AES_ECB_Encrypt(key: bytes) -> AES:
|
||||
'''
|
||||
Create AES encryption context in ECB mode
|
||||
'''
|
||||
return AES(AES.ECB | AES.Encrypt, key)
|
||||
|
||||
|
||||
def AES_ECB_Decrypt(key: bytes) -> AES:
|
||||
'''
|
||||
Create AES decryption context in ECB mode
|
||||
'''
|
||||
return AES(AES.ECB | AES.Decrypt, key)
|
||||
|
||||
|
||||
def AES_CBC_Encrypt(key: bytes, iv: bytes) -> AES:
|
||||
'''
|
||||
Create AES encryption context in CBC mode
|
||||
'''
|
||||
return AES(AES.CBC | AES.Encrypt, key, iv)
|
||||
|
||||
|
||||
def AES_CBC_Decrypt(key: bytes, iv: bytes) -> AES:
|
||||
'''
|
||||
Create AES decryption context in CBC mode
|
||||
'''
|
||||
return AES(AES.CBC | AES.Decrypt, key, iv)
|
||||
|
||||
|
||||
def AES_CFB_Encrypt(key: bytes, iv: bytes) -> AES:
|
||||
'''
|
||||
Create AES encryption context in CFB mode
|
||||
'''
|
||||
return AES(AES.CFB | AES.Encrypt, key, iv)
|
||||
|
||||
|
||||
def AES_CFB_Decrypt(key: bytes, iv: bytes) -> AES:
|
||||
'''
|
||||
Create AES decryption context in CFB mode
|
||||
'''
|
||||
return AES(AES.CFB | AES.Decrypt, key, iv)
|
||||
|
||||
|
||||
def AES_OFB_Encrypt(key: bytes, iv: bytes) -> AES:
|
||||
'''
|
||||
Create AES encryption context in OFB mode
|
||||
'''
|
||||
return AES(AES.OFB | AES.Encrypt, key, iv)
|
||||
|
||||
|
||||
def AES_OFB_Decrypt(key: bytes, iv: bytes) -> AES:
|
||||
'''
|
||||
Create AES decryption context in OFB mode
|
||||
'''
|
||||
return AES(AES.OFB | AES.Decrypt, key, iv)
|
||||
|
||||
|
||||
def AES_CTR_Encrypt(key: bytes) -> AES:
|
||||
'''
|
||||
Create AES encryption context in CTR mode
|
||||
'''
|
||||
return AES(AES.CTR | AES.Encrypt, key)
|
||||
|
||||
|
||||
def AES_CTR_Decrypt(key: bytes) -> AES:
|
||||
'''
|
||||
Create AES decryption context in CTR mode
|
||||
|
@ -16,6 +16,7 @@
|
||||
# 58 character alphabet used
|
||||
_alphabet = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
|
||||
|
||||
|
||||
def encode(data: bytes) -> str:
|
||||
'''
|
||||
Convert bytes to base58 encoded string.
|
||||
@ -67,6 +68,7 @@ def encode_check(data: bytes, digestfunc=None) -> str:
|
||||
digestfunc = lambda x: sha256(sha256(x).digest()).digest()[:4]
|
||||
return encode(data + digestfunc(data))
|
||||
|
||||
|
||||
def decode_check(string: str, digestfunc=None) -> bytes:
|
||||
'''
|
||||
Convert base58 encoded string to bytes and verify checksum.
|
||||
|
@ -1,5 +1,6 @@
|
||||
|
||||
class Hmac:
|
||||
|
||||
def __init__(self, key, msg, digestmod):
|
||||
self.__digestmod = digestmod
|
||||
self.__inner = digestmod()
|
||||
|
@ -20,29 +20,37 @@ _leveldict = {
|
||||
level = NOTSET
|
||||
color = True
|
||||
|
||||
|
||||
def _log(name, mlevel, msg, *args):
|
||||
if __debug__ and mlevel >= level:
|
||||
if color:
|
||||
fmt = '%d \x1b[35m%s\x1b[0m %s \x1b[' + _leveldict[mlevel][1] + 'm' + msg + '\x1b[0m'
|
||||
fmt = '%d \x1b[35m%s\x1b[0m %s \x1b[' + \
|
||||
_leveldict[mlevel][1] + 'm' + msg + '\x1b[0m'
|
||||
else:
|
||||
fmt = '%d %s %s ' + msg
|
||||
print(fmt % ((utime.ticks_us(), name, _leveldict[mlevel][0]) + args))
|
||||
|
||||
|
||||
def debug(name, msg, *args):
|
||||
_log(name, DEBUG, msg, *args)
|
||||
|
||||
|
||||
def info(name, msg, *args):
|
||||
_log(name, INFO, msg, *args)
|
||||
|
||||
|
||||
def warning(name, msg, *args):
|
||||
_log(name, WARNING, msg, *args)
|
||||
|
||||
|
||||
def error(name, msg, *args):
|
||||
_log(name, ERROR, msg, *args)
|
||||
|
||||
|
||||
def exception(name, exc):
|
||||
_log(name, ERROR, 'exception:')
|
||||
sys.print_exception(exc)
|
||||
|
||||
|
||||
def critical(name, msg, *args):
|
||||
_log(name, CRITICAL, msg, *args)
|
||||
|
@ -287,6 +287,7 @@ class Wait(Syscall):
|
||||
self.exit()
|
||||
raise
|
||||
|
||||
|
||||
select = Select
|
||||
sleep = Sleep
|
||||
wait = Wait
|
||||
|
@ -3,6 +3,7 @@ try:
|
||||
except ImportError:
|
||||
resdata = None
|
||||
|
||||
|
||||
def load(name):
|
||||
'''
|
||||
Loads resource of a given name as bytes.
|
||||
@ -12,6 +13,7 @@ def load(name):
|
||||
with open(name, 'rb') as f:
|
||||
return f.read()
|
||||
|
||||
|
||||
def gettext(message):
|
||||
'''
|
||||
Returns localized string. This function is aliased to _.
|
||||
|
@ -116,8 +116,14 @@ class Button(Widget):
|
||||
ax, ay, aw, ah = self.area
|
||||
tx = ax + aw // 2
|
||||
ty = ay + ah // 2 + 8
|
||||
display.bar_radius(ax, ay, aw, ah, style['border-color'], ui.BLACK, style['radius'])
|
||||
display.bar_radius(ax + 1, ay + 1, aw - 2, ah - 2, style['bg-color'], style['border-color'], style['radius'])
|
||||
display.bar_radius(ax, ay, aw, ah,
|
||||
style['border-color'],
|
||||
ui.BLACK,
|
||||
style['radius'])
|
||||
display.bar_radius(ax + 1, ay + 1, aw - 2, ah - 2,
|
||||
style['bg-color'],
|
||||
style['border-color'],
|
||||
style['radius'])
|
||||
|
||||
if isinstance(self.content, str):
|
||||
display.text_center(tx, ty, self.content,
|
||||
|
@ -11,6 +11,7 @@ CANCELLED = const(2)
|
||||
|
||||
|
||||
class ConfirmDialog(Widget):
|
||||
|
||||
def __init__(self, content=None, confirm='Confirm', cancel='Cancel'):
|
||||
self.content = content
|
||||
if cancel is not None:
|
||||
@ -44,6 +45,7 @@ class ConfirmDialog(Widget):
|
||||
|
||||
|
||||
class HoldToConfirmDialog(Widget):
|
||||
|
||||
def __init__(self, content=None, hold='Hold to confirm', *args, **kwargs):
|
||||
self.button = Button((0, 240 - 48, 240, 48), hold,
|
||||
normal_style=CONFIRM_BUTTON,
|
||||
|
@ -10,8 +10,8 @@ class Container(Widget):
|
||||
for child in self.children:
|
||||
child.render()
|
||||
|
||||
def send(self, event, pos):
|
||||
def touch(self, event, pos):
|
||||
for child in self.children:
|
||||
result = child.send(event, pos)
|
||||
result = child.touch(event, pos)
|
||||
if result is not None:
|
||||
return result
|
||||
|
@ -43,7 +43,7 @@ def compute_mask(text):
|
||||
return mask
|
||||
|
||||
|
||||
class KeyboardMultiTap:
|
||||
class KeyboardMultiTap(ui.Widget):
|
||||
|
||||
def __init__(self, content=''):
|
||||
self.content = content
|
||||
@ -162,7 +162,7 @@ def zoom_buttons(keys, upper=False):
|
||||
return [Button(cell_area(i, n_x, n_y), key) for i, key in enumerate(keys)]
|
||||
|
||||
|
||||
class KeyboardZooming:
|
||||
class KeyboardZooming(ui.Widget):
|
||||
|
||||
def __init__(self, content='', uppercase=True):
|
||||
self.content = content
|
||||
|
@ -19,7 +19,7 @@ DEFAULT_LOADER_ACTIVE = {
|
||||
_LOADER_MSEC = const(1000)
|
||||
|
||||
|
||||
class Loader:
|
||||
class Loader(ui.Widget):
|
||||
|
||||
def __init__(self, normal_style=None, active_style=None):
|
||||
self.start_ticks_ms = None
|
||||
|
@ -21,7 +21,7 @@ def generate_digits():
|
||||
return digits
|
||||
|
||||
|
||||
class PinMatrix():
|
||||
class PinMatrix(ui.Widget):
|
||||
|
||||
def __init__(self, label, pin=''):
|
||||
self.label = label
|
||||
@ -67,10 +67,10 @@ class PinMatrix():
|
||||
# display.bar(0, 95, 240, 2, ui.blend(ui.BLACK, ui.WHITE, 0.25))
|
||||
# display.bar(0, 142, 240, 2, ui.blend(ui.BLACK, ui.WHITE, 0.25))
|
||||
|
||||
def send(self, event, pos):
|
||||
if self.clear_button.send(event, pos) == BTN_CLICKED:
|
||||
def touch(self, event, pos):
|
||||
if self.clear_button.touch(event, pos) == BTN_CLICKED:
|
||||
self.pin = ''
|
||||
for btn in self.pin_buttons:
|
||||
if btn.send(event, pos) == BTN_CLICKED:
|
||||
if btn.touch(event, pos) == BTN_CLICKED:
|
||||
if len(self.pin) < 9:
|
||||
self.pin += btn.content
|
||||
|
@ -1,7 +1,7 @@
|
||||
from trezor import ui
|
||||
|
||||
|
||||
class Qr:
|
||||
class Qr(ui.Widget):
|
||||
|
||||
def __init__(self, data, pos, scale):
|
||||
self.data = data
|
||||
@ -10,6 +10,3 @@ class Qr:
|
||||
|
||||
def render(self):
|
||||
ui.display.qrcode(self.pos[0], self.pos[1], self.data, self.scale)
|
||||
|
||||
def send(self, event, pos):
|
||||
pass
|
||||
|
@ -13,7 +13,8 @@ SWIPE_LEFT = const(90)
|
||||
SWIPE_RIGHT = const(270)
|
||||
|
||||
|
||||
class Swipe():
|
||||
class Swipe(ui.Widget):
|
||||
|
||||
def __init__(self, area=None, absolute=False):
|
||||
self.area = area or (0, 0, ui.SCREEN, ui.SCREEN)
|
||||
self.absolute = absolute
|
||||
@ -22,7 +23,7 @@ class Swipe():
|
||||
self.light_origin = None
|
||||
self.light_target = ui.BACKLIGHT_NONE
|
||||
|
||||
def send(self, event, pos):
|
||||
def touch(self, event, pos):
|
||||
|
||||
if not self.absolute:
|
||||
pos = rotate_coords(pos)
|
||||
@ -85,10 +86,3 @@ class Swipe():
|
||||
self.start_pos = None
|
||||
self.start_time = 0
|
||||
ui.display.backlight(self.light_origin)
|
||||
|
||||
def __iter__(self):
|
||||
while True:
|
||||
event, *pos = yield loop.Select(loop.TOUCH)
|
||||
result = self.send(event, pos)
|
||||
if result is not None:
|
||||
return result
|
||||
|
Loading…
Reference in New Issue
Block a user