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

trezor: code style

This commit is contained in:
Jan Pochyla 2017-05-31 19:32:40 +02:00
parent 3cb89f3ae7
commit c6545b9b6d
8 changed files with 27 additions and 21 deletions

View File

@ -2,6 +2,7 @@ from TrezorConfig import Config
_config = Config()
def get(app: int, key: int) -> bytes:
return _config.get(app, key)

View File

@ -1,3 +1,4 @@
def encode_length(l: int) -> bytes:
if l < 0x80:
return bytes([l])
@ -8,12 +9,14 @@ def encode_length(l: int) -> bytes:
else:
raise ValueError
def encode_int(i: bytes) -> bytes:
i = i.lstrip(b'\x00')
if i[0] >= 0x80:
i = b'\x00' + i
return b'\x02' + encode_length(len(i)) + i
def encode_seq(seq: tuple) -> bytes:
res = b''
for i in seq:

View File

@ -1,8 +1,3 @@
def new(key, msg, digestmod) -> Hmac:
'''
Creates a HMAC context object.
'''
return Hmac(key, msg, digestmod)
class Hmac:
def __init__(self, key, msg, digestmod):
@ -33,3 +28,8 @@ class Hmac:
return outer.digest()
def new(key, msg, digestmod) -> Hmac:
'''
Creates a HMAC context object.
'''
return Hmac(key, msg, digestmod)

View File

@ -1,3 +1,4 @@
def int_to_bytes(x: int) -> bytes:
if x == 0:
return b''
@ -7,6 +8,7 @@ def int_to_bytes(x: int) -> bytes:
x //= 256
return bytes(reversed(r))
def encode_length(l: int, is_list: bool) -> bytes:
offset = 0xC0 if is_list else 0x80
if l < 56:
@ -17,6 +19,7 @@ def encode_length(l: int, is_list: bool) -> bytes:
else:
raise ValueError('Input too long')
def encode(data) -> bytes:
if isinstance(data, int):
return encode(int_to_bytes(data))

View File

@ -19,7 +19,7 @@ DEFAULT_LOADER_ACTIVE = {
_LOADER_MSEC = const(1000)
class Loader():
class Loader:
def __init__(self, normal_style=None, active_style=None):
self.start_ticks_ms = None

View File

@ -1,8 +1,8 @@
from micropython import const
from trezor.crypto import random
from trezor import ui, res
from .button import Button, BTN_CLICKED, CLEAR_BUTTON, CLEAR_BUTTON_ACTIVE
from . import display
from trezor.crypto import random
from trezor.ui import display
from treozr.ui.button import Button, BTN_CLICKED, CLEAR_BUTTON, CLEAR_BUTTON_ACTIVE
def digit_area(i):

View File

@ -49,4 +49,5 @@ def render_scrollbar(page, page_count):
if i != page:
ui.display.bar_radius(x, y + i * padding, size,
size, ui.DARK_GREY, ui.BLACK, 4)
ui.display.bar_radius(x, y + page * padding, size, size, ui.WHITE, ui.BLACK, 4)
ui.display.bar_radius(x, y + page * padding, size,
size, ui.WHITE, ui.BLACK, 4)

View File

@ -16,7 +16,6 @@ def _unimport_func(func):
finally:
for mod in sys.modules:
if mod not in mods:
log.debug(__name__, 'unimport %s', mod)
del sys.modules[mod]
gc.collect()
return ret
@ -31,7 +30,6 @@ def _unimport_genfunc(genfunc):
finally:
for mod in sys.modules:
if mod not in mods:
log.debug(__name__, 'unimport %s', mod)
del sys.modules[mod]
gc.collect()
return ret