tests gen_digital_signature_tests: Fix mypy issues

This commit is contained in:
Angus Gratton
2021-06-18 10:51:43 +10:00
committed by Michael (XIAO Xufeng)
parent b06dba7823
commit 867f13c6b7
2 changed files with 6 additions and 6 deletions

View File

@@ -8,11 +8,12 @@ import struct
from cryptography.hazmat.backends import default_backend from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives.asymmetric import rsa from cryptography.hazmat.primitives.asymmetric import rsa
from cryptography.hazmat.primitives.asymmetric.rsa import _modinv as modinv # type: ignore
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
from cryptography.utils import int_to_bytes from cryptography.utils import int_to_bytes
def number_as_bignum_words(number): def number_as_bignum_words(number): # type: (int) -> str
""" """
Given a number, format result as a C array of words Given a number, format result as a C array of words
(little-endian, same as ESP32 RSA peripheral or mbedTLS) (little-endian, same as ESP32 RSA peripheral or mbedTLS)
@@ -24,17 +25,17 @@ def number_as_bignum_words(number):
return '{ ' + ', '.join(result) + ' }' return '{ ' + ', '.join(result) + ' }'
def number_as_bytes(number, pad_bits=None): def number_as_bytes(number, pad_bits=None): # type: (int, int) -> bytes
""" """
Given a number, format as a little endian array of bytes Given a number, format as a little endian array of bytes
""" """
result = int_to_bytes(number)[::-1] result = int_to_bytes(number)[::-1] # type: bytes
while pad_bits is not None and len(result) < (pad_bits // 8): while pad_bits is not None and len(result) < (pad_bits // 8):
result += b'\x00' result += b'\x00'
return result return result
def bytes_as_char_array(b): def bytes_as_char_array(b): # type: (bytes) -> str
""" """
Given a sequence of bytes, format as a char array Given a sequence of bytes, format as a char array
""" """
@@ -96,7 +97,7 @@ with open('digital_signature_test_cases.h', 'w') as f:
rr = 1 << (key_size * 2) rr = 1 << (key_size * 2)
rinv = rr % pub_numbers.n rinv = rr % pub_numbers.n
mprime = - rsa._modinv(M, 1 << 32) mprime = - modinv(M, 1 << 32)
mprime &= 0xFFFFFFFF mprime &= 0xFFFFFFFF
length = key_size // 32 - 1 length = key_size // 32 - 1

View File

@@ -3,7 +3,6 @@ components/efuse/efuse_table_gen.py
components/efuse/test_efuse_host/efuse_tests.py components/efuse/test_efuse_host/efuse_tests.py
components/esp_local_ctrl/python/esp_local_ctrl_pb2.py components/esp_local_ctrl/python/esp_local_ctrl_pb2.py
components/esp_netif/test_apps/component_ut_test.py components/esp_netif/test_apps/component_ut_test.py
components/esp_hw_support/test/gen_digital_signature_tests.py
components/espcoredump/corefile/elf.py components/espcoredump/corefile/elf.py
components/espcoredump/corefile/gdb.py components/espcoredump/corefile/gdb.py
components/espcoredump/test/test_espcoredump.py components/espcoredump/test/test_espcoredump.py