From 45787307cac35bee04c732244162087e862afa4d Mon Sep 17 00:00:00 2001 From: matejcik Date: Thu, 9 Dec 2021 15:00:11 +0100 Subject: [PATCH] style(core): support AnyStr in all hash function arguments --- .../modtrezorcrypto-blake256.h | 4 +-- .../modtrezorcrypto/modtrezorcrypto-blake2b.h | 2 +- .../modtrezorcrypto/modtrezorcrypto-blake2s.h | 2 +- .../modtrezorcrypto/modtrezorcrypto-groestl.h | 4 +-- .../modtrezorcrypto-ripemd160.h | 4 +-- .../modtrezorcrypto/modtrezorcrypto-sha1.h | 4 +-- .../modtrezorcrypto/modtrezorcrypto-sha256.h | 4 +-- .../modtrezorcrypto-sha3-256.h | 2 +- .../modtrezorcrypto-sha3-512.h | 2 +- .../modtrezorcrypto/modtrezorcrypto-sha512.h | 4 +-- core/embed/extmod/modtrezorio/modtrezorio.c | 4 +-- .../mocks/generated/trezorcrypto/__init__.pyi | 32 +++++++++---------- core/mocks/generated/trezorio/__init__.pyi | 3 +- 13 files changed, 34 insertions(+), 37 deletions(-) diff --git a/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-blake256.h b/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-blake256.h index e78665f46..95d91619f 100644 --- a/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-blake256.h +++ b/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-blake256.h @@ -37,7 +37,7 @@ typedef struct _mp_obj_Blake256_t { STATIC mp_obj_t mod_trezorcrypto_Blake256_update(mp_obj_t self, mp_obj_t data); -/// def __init__(self, data: bytes | None = None) -> None: +/// def __init__(self, __data: AnyStr | None = None) -> None: /// """ /// Creates a hash context object. /// """ @@ -55,7 +55,7 @@ STATIC mp_obj_t mod_trezorcrypto_Blake256_make_new(const mp_obj_type_t *type, return MP_OBJ_FROM_PTR(o); } -/// def update(self, data: bytes) -> None: +/// def update(self, __data: AnyStr) -> None: /// """ /// Update the hash context with hashed data. /// """ diff --git a/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-blake2b.h b/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-blake2b.h index 2fa7529cb..687c5a73c 100644 --- a/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-blake2b.h +++ b/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-blake2b.h @@ -109,7 +109,7 @@ STATIC mp_obj_t mod_trezorcrypto_Blake2b_make_new(const mp_obj_type_t *type, return MP_OBJ_FROM_PTR(o); } -/// def update(self, data: bytes) -> None: +/// def update(self, __data: AnyStr) -> None: /// """ /// Update the hash context with hashed data. /// """ diff --git a/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-blake2s.h b/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-blake2s.h index 2e53a9e7a..4cf175405 100644 --- a/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-blake2s.h +++ b/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-blake2s.h @@ -109,7 +109,7 @@ STATIC mp_obj_t mod_trezorcrypto_Blake2s_make_new(const mp_obj_type_t *type, return MP_OBJ_FROM_PTR(o); } -/// def update(self, data: bytes) -> None: +/// def update(self, __data: AnyStr) -> None: /// """ /// Update the hash context with hashed data. /// """ diff --git a/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-groestl.h b/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-groestl.h index 6d79bf756..089bc46b3 100644 --- a/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-groestl.h +++ b/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-groestl.h @@ -41,7 +41,7 @@ typedef struct _mp_obj_Groestl512_t { STATIC mp_obj_t mod_trezorcrypto_Groestl512_update(mp_obj_t self, mp_obj_t data); -/// def __init__(self, data: bytes | None = None) -> None: +/// def __init__(self, __data: AnyStr | None = None) -> None: /// """ /// Creates a hash context object. /// """ @@ -58,7 +58,7 @@ STATIC mp_obj_t mod_trezorcrypto_Groestl512_make_new(const mp_obj_type_t *type, return MP_OBJ_FROM_PTR(o); } -/// def update(self, data: bytes) -> None: +/// def update(self, __data: AnyStr) -> None: /// """ /// Update the hash context with hashed data. /// """ diff --git a/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-ripemd160.h b/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-ripemd160.h index 2e45a6568..7a9f25822 100644 --- a/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-ripemd160.h +++ b/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-ripemd160.h @@ -37,7 +37,7 @@ typedef struct _mp_obj_Ripemd160_t { STATIC mp_obj_t mod_trezorcrypto_Ripemd160_update(mp_obj_t self, mp_obj_t data); -/// def __init__(self, data: bytes | None = None) -> None: +/// def __init__(self, __data: AnyStr | None = None) -> None: /// """ /// Creates a hash context object. /// """ @@ -55,7 +55,7 @@ STATIC mp_obj_t mod_trezorcrypto_Ripemd160_make_new(const mp_obj_type_t *type, return MP_OBJ_FROM_PTR(o); } -/// def update(self, data: bytes) -> None: +/// def update(self, __data: AnyStr) -> None: /// """ /// Update the hash context with hashed data. /// """ diff --git a/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-sha1.h b/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-sha1.h index f664e167d..f00b1bd73 100644 --- a/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-sha1.h +++ b/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-sha1.h @@ -37,7 +37,7 @@ typedef struct _mp_obj_Sha1_t { STATIC mp_obj_t mod_trezorcrypto_Sha1_update(mp_obj_t self, mp_obj_t data); -/// def __init__(self, data: bytes | None = None) -> None: +/// def __init__(self, __data: AnyStr | None = None) -> None: /// """ /// Creates a hash context object. /// """ @@ -55,7 +55,7 @@ STATIC mp_obj_t mod_trezorcrypto_Sha1_make_new(const mp_obj_type_t *type, return MP_OBJ_FROM_PTR(o); } -/// def update(self, data: bytes) -> None: +/// def update(self, __data: AnyStr) -> None: /// """ /// Update the hash context with hashed data. /// """ diff --git a/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-sha256.h b/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-sha256.h index 960d27aaa..cb4282c10 100644 --- a/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-sha256.h +++ b/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-sha256.h @@ -37,7 +37,7 @@ typedef struct _mp_obj_Sha256_t { STATIC mp_obj_t mod_trezorcrypto_Sha256_update(mp_obj_t self, mp_obj_t data); -/// def __init__(self, data: bytes | None = None) -> None: +/// def __init__(self, __data: AnyStr | None = None) -> None: /// """ /// Creates a hash context object. /// """ @@ -55,7 +55,7 @@ STATIC mp_obj_t mod_trezorcrypto_Sha256_make_new(const mp_obj_type_t *type, return MP_OBJ_FROM_PTR(o); } -/// def update(self, data: bytes) -> None: +/// def update(self, __data: AnyStr) -> None: /// """ /// Update the hash context with hashed data. /// """ diff --git a/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-sha3-256.h b/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-sha3-256.h index b6c5ebcb2..3fd377005 100644 --- a/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-sha3-256.h +++ b/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-sha3-256.h @@ -72,7 +72,7 @@ STATIC mp_obj_t mod_trezorcrypto_Sha3_256_make_new(const mp_obj_type_t *type, return MP_OBJ_FROM_PTR(o); } -/// def update(self, data: bytes) -> None: +/// def update(self, __data: AnyStr) -> None: /// """ /// Update the hash context with hashed data. /// """ diff --git a/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-sha3-512.h b/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-sha3-512.h index 5ab89b308..61a68ca8e 100644 --- a/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-sha3-512.h +++ b/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-sha3-512.h @@ -72,7 +72,7 @@ STATIC mp_obj_t mod_trezorcrypto_Sha3_512_make_new(const mp_obj_type_t *type, return MP_OBJ_FROM_PTR(o); } -/// def update(self, data: bytes) -> None: +/// def update(self, __data: AnyStr) -> None: /// """ /// Update the hash context with hashed data. /// """ diff --git a/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-sha512.h b/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-sha512.h index eec67d1ce..547ce6fd8 100644 --- a/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-sha512.h +++ b/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-sha512.h @@ -37,7 +37,7 @@ typedef struct _mp_obj_Sha512_t { STATIC mp_obj_t mod_trezorcrypto_Sha512_update(mp_obj_t self, mp_obj_t data); -/// def __init__(self, data: bytes | None = None) -> None: +/// def __init__(self, __data: AnyStr | None = None) -> None: /// """ /// Creates a hash context object. /// """ @@ -54,7 +54,7 @@ STATIC mp_obj_t mod_trezorcrypto_Sha512_make_new(const mp_obj_type_t *type, return MP_OBJ_FROM_PTR(o); } -/// def update(self, data: bytes) -> None: +/// def update(self, __data: AnyStr) -> None: /// """ /// Update the hash context with hashed data. /// """ diff --git a/core/embed/extmod/modtrezorio/modtrezorio.c b/core/embed/extmod/modtrezorio/modtrezorio.c index 7f6c3bcc5..70b96ad41 100644 --- a/core/embed/extmod/modtrezorio/modtrezorio.c +++ b/core/embed/extmod/modtrezorio/modtrezorio.c @@ -51,6 +51,7 @@ #endif /// package: trezorio.__init__ +/// from . import fatfs, sdcard /// POLL_READ: int # wait until interface is readable and return read data /// POLL_WRITE: int # wait until interface is writable @@ -68,9 +69,6 @@ /// WireInterface = Union[HID, WebUSB] -/// if False: -/// from . import fatfs, sdcard - STATIC const mp_rom_map_elem_t mp_module_trezorio_globals_table[] = { {MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_trezorio)}, diff --git a/core/mocks/generated/trezorcrypto/__init__.pyi b/core/mocks/generated/trezorcrypto/__init__.pyi index 290d89e91..144560ef8 100644 --- a/core/mocks/generated/trezorcrypto/__init__.pyi +++ b/core/mocks/generated/trezorcrypto/__init__.pyi @@ -41,12 +41,12 @@ class blake256: block_size: int digest_size: int - def __init__(self, data: bytes | None = None) -> None: + def __init__(self, __data: AnyStr | None = None) -> None: """ Creates a hash context object. """ - def update(self, data: bytes) -> None: + def update(self, __data: AnyStr) -> None: """ Update the hash context with hashed data. """ @@ -76,7 +76,7 @@ class blake2b: Creates a hash context object. """ - def update(self, data: bytes) -> None: + def update(self, __data: AnyStr) -> None: """ Update the hash context with hashed data. """ @@ -106,7 +106,7 @@ class blake2s: Creates a hash context object. """ - def update(self, data: bytes) -> None: + def update(self, __data: AnyStr) -> None: """ Update the hash context with hashed data. """ @@ -162,12 +162,12 @@ class groestl512: block_size: int digest_size: int - def __init__(self, data: bytes | None = None) -> None: + def __init__(self, __data: AnyStr | None = None) -> None: """ Creates a hash context object. """ - def update(self, data: bytes) -> None: + def update(self, __data: AnyStr) -> None: """ Update the hash context with hashed data. """ @@ -246,12 +246,12 @@ class ripemd160: block_size: int digest_size: int - def __init__(self, data: bytes | None = None) -> None: + def __init__(self, __data: AnyStr | None = None) -> None: """ Creates a hash context object. """ - def update(self, data: bytes) -> None: + def update(self, __data: AnyStr) -> None: """ Update the hash context with hashed data. """ @@ -270,12 +270,12 @@ class sha1: block_size: int digest_size: int - def __init__(self, data: bytes | None = None) -> None: + def __init__(self, __data: AnyStr | None = None) -> None: """ Creates a hash context object. """ - def update(self, data: bytes) -> None: + def update(self, __data: AnyStr) -> None: """ Update the hash context with hashed data. """ @@ -294,12 +294,12 @@ class sha256: block_size: int digest_size: int - def __init__(self, data: bytes | None = None) -> None: + def __init__(self, __data: AnyStr | None = None) -> None: """ Creates a hash context object. """ - def update(self, data: bytes) -> None: + def update(self, __data: AnyStr) -> None: """ Update the hash context with hashed data. """ @@ -327,7 +327,7 @@ class sha3_256: Creates a hash context object. """ - def update(self, data: bytes) -> None: + def update(self, __data: AnyStr) -> None: """ Update the hash context with hashed data. """ @@ -360,7 +360,7 @@ class sha3_512: Creates a hash context object. """ - def update(self, data: bytes) -> None: + def update(self, __data: AnyStr) -> None: """ Update the hash context with hashed data. """ @@ -384,12 +384,12 @@ class sha512: block_size: int digest_size: int - def __init__(self, data: bytes | None = None) -> None: + def __init__(self, __data: AnyStr | None = None) -> None: """ Creates a hash context object. """ - def update(self, data: bytes) -> None: + def update(self, __data: AnyStr) -> None: """ Update the hash context with hashed data. """ diff --git a/core/mocks/generated/trezorio/__init__.pyi b/core/mocks/generated/trezorio/__init__.pyi index 78a654a78..4435c2c95 100644 --- a/core/mocks/generated/trezorio/__init__.pyi +++ b/core/mocks/generated/trezorio/__init__.pyi @@ -190,6 +190,7 @@ class WebUSB: """ Sends message using USB WebUSB (device) or UDP (emulator). """ +from . import fatfs, sdcard POLL_READ: int # wait until interface is readable and return read data POLL_WRITE: int # wait until interface is writable TOUCH: int # interface id of the touch events @@ -202,5 +203,3 @@ BUTTON_RELEASED: int # button up event BUTTON_LEFT: int # button number of left button BUTTON_RIGHT: int # button number of right button WireInterface = Union[HID, WebUSB] -if False: - from . import fatfs, sdcard