mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-22 15:38:11 +00:00
style(core/tests): fix warnings
This commit is contained in:
parent
d44a51ef49
commit
d081f185b1
@ -1,7 +1,7 @@
|
|||||||
# flake8: noqa: F403,F405
|
# flake8: noqa: F403,F405
|
||||||
from common import * # isort:skip
|
from common import * # isort:skip
|
||||||
|
|
||||||
if utils.INTERNAL_MODEL in ("T2T1", ):
|
if utils.INTERNAL_MODEL in ("T2T1", ): # pylint: disable=internal-model-tuple-comparison
|
||||||
from trezor.crypto import bip39
|
from trezor.crypto import bip39
|
||||||
from trezor.enums import AmountUnit, OutputScriptType
|
from trezor.enums import AmountUnit, OutputScriptType
|
||||||
from trezor.enums.RequestType import TXFINISHED, TXINPUT, TXMETA, TXOUTPUT
|
from trezor.enums.RequestType import TXFINISHED, TXINPUT, TXMETA, TXOUTPUT
|
||||||
@ -406,5 +406,8 @@ class TestSignTxDecred(unittest.TestCase):
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
if utils.INTERNAL_MODEL in ("T2T1",):
|
if utils.INTERNAL_MODEL in ( # pylint: disable=internal-model-tuple-comparison
|
||||||
|
"T2T1",
|
||||||
|
):
|
||||||
|
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
@ -628,7 +628,7 @@ class TestCardanoAddress(unittest.TestCase):
|
|||||||
|
|
||||||
for (
|
for (
|
||||||
network_id,
|
network_id,
|
||||||
address_type,
|
_,
|
||||||
address_parameters,
|
address_parameters,
|
||||||
expected_address,
|
expected_address,
|
||||||
) in test_vectors:
|
) in test_vectors:
|
||||||
|
@ -23,7 +23,9 @@ class TestCoins(unittest.TestCase):
|
|||||||
("ZEC", "Zcash", 7352),
|
("ZEC", "Zcash", 7352),
|
||||||
("TAZ", "Zcash Testnet", 7461),
|
("TAZ", "Zcash Testnet", 7461),
|
||||||
]
|
]
|
||||||
if utils.INTERNAL_MODEL in ("T2T1",):
|
if utils.INTERNAL_MODEL in ( # pylint: disable=internal-model-tuple-comparison
|
||||||
|
"T2T1",
|
||||||
|
):
|
||||||
ref.extend(
|
ref.extend(
|
||||||
[
|
[
|
||||||
("NMC", "Namecoin", 52),
|
("NMC", "Namecoin", 52),
|
||||||
|
@ -58,7 +58,7 @@ class TestDecodeDefinition(unittest.TestCase):
|
|||||||
|
|
||||||
def test_missing_signature(self):
|
def test_missing_signature(self):
|
||||||
payload = make_payload()
|
payload = make_payload()
|
||||||
proof, signature = sign_payload(payload, [])
|
proof, _ = sign_payload(payload, [])
|
||||||
self.assertFailed(payload + proof)
|
self.assertFailed(payload + proof)
|
||||||
|
|
||||||
def test_mangled_payload(self):
|
def test_mangled_payload(self):
|
||||||
@ -69,7 +69,7 @@ class TestDecodeDefinition(unittest.TestCase):
|
|||||||
|
|
||||||
def test_proof_length_mismatch(self):
|
def test_proof_length_mismatch(self):
|
||||||
payload = make_payload()
|
payload = make_payload()
|
||||||
proof, signature = sign_payload(payload, [])
|
_, signature = sign_payload(payload, [])
|
||||||
bad_proof = b"\x01"
|
bad_proof = b"\x01"
|
||||||
self.assertFailed(payload + bad_proof + signature)
|
self.assertFailed(payload + bad_proof + signature)
|
||||||
|
|
||||||
@ -133,13 +133,13 @@ class TestEthereumDefinitions(unittest.TestCase):
|
|||||||
return
|
return
|
||||||
if what is tokens.UNKNOWN_TOKEN:
|
if what is tokens.UNKNOWN_TOKEN:
|
||||||
return
|
return
|
||||||
self.fail("Expected UNKNOWN_*, got %r" % what)
|
self.fail(f"Expected UNKNOWN_*, got {what}")
|
||||||
|
|
||||||
def assertKnown(self, what: t.Any) -> None:
|
def assertKnown(self, what: t.Any) -> None:
|
||||||
if not EthereumNetworkInfo.is_type_of(
|
if not EthereumNetworkInfo.is_type_of(
|
||||||
what
|
what
|
||||||
) and not EthereumTokenInfo.is_type_of(what):
|
) and not EthereumTokenInfo.is_type_of(what):
|
||||||
self.fail("Expected network / token info, got %r" % what)
|
self.fail(f"Expected network / token info, got {what}")
|
||||||
if what is networks.UNKNOWN_NETWORK:
|
if what is networks.UNKNOWN_NETWORK:
|
||||||
self.fail("Expected known network, got UNKNOWN_NETWORK")
|
self.fail("Expected known network, got UNKNOWN_NETWORK")
|
||||||
if what is tokens.UNKNOWN_TOKEN:
|
if what is tokens.UNKNOWN_TOKEN:
|
||||||
|
@ -135,6 +135,7 @@ def parse_type_n(type_name: str) -> int:
|
|||||||
buf += char
|
buf += char
|
||||||
else:
|
else:
|
||||||
return int("".join(reversed(buf)))
|
return int("".join(reversed(buf)))
|
||||||
|
raise ValueError(f"Invalid type name: {type_name}")
|
||||||
|
|
||||||
|
|
||||||
def parse_array_n(type_name: str) -> Union[int, str]:
|
def parse_array_n(type_name: str) -> Union[int, str]:
|
||||||
|
@ -175,19 +175,19 @@ class TestSlip39(unittest.TestCase):
|
|||||||
storage.recovery.set_in_progress(True)
|
storage.recovery.set_in_progress(True)
|
||||||
|
|
||||||
words = MNEMONIC_SLIP39_BASIC_20_3of6[0]
|
words = MNEMONIC_SLIP39_BASIC_20_3of6[0]
|
||||||
secret, share = process_slip39(words)
|
secret, _ = process_slip39(words)
|
||||||
self.assertIsNone(secret)
|
self.assertIsNone(secret)
|
||||||
|
|
||||||
# same mnemonic
|
# same mnemonic
|
||||||
words = MNEMONIC_SLIP39_BASIC_20_3of6[0]
|
words = MNEMONIC_SLIP39_BASIC_20_3of6[0]
|
||||||
with self.assertRaises(RuntimeError):
|
with self.assertRaises(RuntimeError):
|
||||||
secret, share = process_slip39(words)
|
secret, _ = process_slip39(words)
|
||||||
self.assertIsNone(secret)
|
self.assertIsNone(secret)
|
||||||
|
|
||||||
# identifier mismatch
|
# identifier mismatch
|
||||||
words = MNEMONIC_SLIP39_ADVANCED_20[0]
|
words = MNEMONIC_SLIP39_ADVANCED_20[0]
|
||||||
with self.assertRaises(RuntimeError):
|
with self.assertRaises(RuntimeError):
|
||||||
secret, share = process_slip39(words)
|
secret, _ = process_slip39(words)
|
||||||
self.assertIsNone(secret)
|
self.assertIsNone(secret)
|
||||||
|
|
||||||
# same identifier but different group settings
|
# same identifier but different group settings
|
||||||
@ -200,7 +200,7 @@ class TestSlip39(unittest.TestCase):
|
|||||||
w[19] = "merchant"
|
w[19] = "merchant"
|
||||||
words = " ".join(w)
|
words = " ".join(w)
|
||||||
with self.assertRaises(RuntimeError):
|
with self.assertRaises(RuntimeError):
|
||||||
secret, share = process_slip39(words)
|
secret, _ = process_slip39(words)
|
||||||
self.assertIsNone(secret)
|
self.assertIsNone(secret)
|
||||||
|
|
||||||
@mock_storage
|
@mock_storage
|
||||||
@ -218,11 +218,11 @@ class TestSlip39(unittest.TestCase):
|
|||||||
check(BackupType.Bip39, ["ocean"])
|
check(BackupType.Bip39, ["ocean"])
|
||||||
|
|
||||||
# let's store two shares in the storage
|
# let's store two shares in the storage
|
||||||
secret, share = process_slip39(
|
secret, _ = process_slip39(
|
||||||
"trash smug adjust ambition criminal prisoner security math cover pecan response pharmacy center criminal salary elbow bracelet lunar briefing dragon"
|
"trash smug adjust ambition criminal prisoner security math cover pecan response pharmacy center criminal salary elbow bracelet lunar briefing dragon"
|
||||||
)
|
)
|
||||||
self.assertIsNone(secret)
|
self.assertIsNone(secret)
|
||||||
secret, share = process_slip39(
|
secret, _ = process_slip39(
|
||||||
"trash smug adjust aide benefit temple round clogs devote prevent type cards clogs plastic aspect paper behavior lunar custody intimate"
|
"trash smug adjust aide benefit temple round clogs devote prevent type cards clogs plastic aspect paper behavior lunar custody intimate"
|
||||||
)
|
)
|
||||||
self.assertIsNone(secret)
|
self.assertIsNone(secret)
|
||||||
@ -244,11 +244,11 @@ class TestSlip39(unittest.TestCase):
|
|||||||
check(BackupType.Slip39_Advanced, ["trash", "smug", "adjust", "ambition"])
|
check(BackupType.Slip39_Advanced, ["trash", "smug", "adjust", "ambition"])
|
||||||
|
|
||||||
# Let's store two more. The group is 4/6 so this group is now complete.
|
# Let's store two more. The group is 4/6 so this group is now complete.
|
||||||
secret, share = process_slip39(
|
secret, _ = process_slip39(
|
||||||
"trash smug adjust arena beard quick language program true hush amount round geology should training practice language diet order ruin"
|
"trash smug adjust arena beard quick language program true hush amount round geology should training practice language diet order ruin"
|
||||||
)
|
)
|
||||||
self.assertIsNone(secret)
|
self.assertIsNone(secret)
|
||||||
secret, share = process_slip39(
|
secret, _ = process_slip39(
|
||||||
"trash smug adjust beam brave sack magazine radar toxic emission domestic cradle vocal petition mule toxic acid hobo welcome downtown"
|
"trash smug adjust beam brave sack magazine radar toxic emission domestic cradle vocal petition mule toxic acid hobo welcome downtown"
|
||||||
)
|
)
|
||||||
self.assertIsNone(secret)
|
self.assertIsNone(secret)
|
||||||
|
@ -14,7 +14,7 @@ class TestMoneroBulletproof(unittest.TestCase):
|
|||||||
ss = crypto.random_scalar()
|
ss = crypto.random_scalar()
|
||||||
s1 = crypto.sc_copy(None, ss)
|
s1 = crypto.sc_copy(None, ss)
|
||||||
s2 = crypto.sc_copy(None, ss)
|
s2 = crypto.sc_copy(None, ss)
|
||||||
for i in range(1, x):
|
for _ in range(1, x):
|
||||||
crypto.sc_mul_into(s1, s1, ss)
|
crypto.sc_mul_into(s1, s1, ss)
|
||||||
|
|
||||||
bp._sc_square_mult(s2, ss, x)
|
bp._sc_square_mult(s2, ss, x)
|
||||||
|
@ -108,7 +108,7 @@ class TestMoneroClsag(unittest.TestCase):
|
|||||||
Cp = crypto.add_keys2_into(None, alpha, amnt, crypto.xmr_H())
|
Cp = crypto.add_keys2_into(None, alpha, amnt, crypto.xmr_H())
|
||||||
|
|
||||||
ring = []
|
ring = []
|
||||||
for i in range(ring_size - 1):
|
for _ in range(ring_size - 1):
|
||||||
tk = TmpKey(
|
tk = TmpKey(
|
||||||
crypto_helpers.encodepoint(
|
crypto_helpers.encodepoint(
|
||||||
crypto.scalarmult_base_into(None, crypto.random_scalar())
|
crypto.scalarmult_base_into(None, crypto.random_scalar())
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
# flake8: noqa: F403,F405
|
# flake8: noqa: F403,F405
|
||||||
from common import *
|
from common import * # isort: skip
|
||||||
from trezor import config, utils
|
from trezor import config, utils
|
||||||
from trezor import log
|
from trezor import log
|
||||||
|
|
||||||
|
@ -139,7 +139,7 @@ class TestZcashSigHasher(unittest.TestCase):
|
|||||||
self.assertEqual(computed_txid, expected_txid)
|
self.assertEqual(computed_txid, expected_txid)
|
||||||
|
|
||||||
# test ZcashSigHasher.signature_digest
|
# test ZcashSigHasher.signature_digest
|
||||||
for txi, expected_sighash, pk in zip(inputs, expected_sighashes, pubkeys):
|
for txi, expected_sighash, _ in zip(inputs, expected_sighashes, pubkeys):
|
||||||
computed_sighash = hasher.signature_digest(txi, txi.script_pubkey)
|
computed_sighash = hasher.signature_digest(txi, txi.script_pubkey)
|
||||||
self.assertEqual(computed_sighash, expected_sighash)
|
self.assertEqual(computed_sighash, expected_sighash)
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ class TestStorageCache(unittest.TestCase):
|
|||||||
session_id = cache.start_session()
|
session_id = cache.start_session()
|
||||||
self.assertEqual(cache.start_session(session_id), session_id)
|
self.assertEqual(cache.start_session(session_id), session_id)
|
||||||
cache.set(KEY, b"A")
|
cache.set(KEY, b"A")
|
||||||
for i in range(cache._MAX_SESSIONS_COUNT):
|
for _ in range(cache._MAX_SESSIONS_COUNT):
|
||||||
cache.start_session()
|
cache.start_session()
|
||||||
self.assertNotEqual(cache.start_session(session_id), session_id)
|
self.assertNotEqual(cache.start_session(session_id), session_id)
|
||||||
self.assertIsNone(cache.get(KEY))
|
self.assertIsNone(cache.get(KEY))
|
||||||
|
@ -26,15 +26,13 @@ class TestCryptoBase32(unittest.TestCase):
|
|||||||
b"zlutoucky kun upel dabelske ody",
|
b"zlutoucky kun upel dabelske ody",
|
||||||
"PJWHK5DPOVRWW6JANN2W4IDVOBSWYIDEMFRGK3DTNNSSA33EPE======",
|
"PJWHK5DPOVRWW6JANN2W4IDVOBSWYIDEMFRGK3DTNNSSA33EPE======",
|
||||||
),
|
),
|
||||||
# fmt: off
|
("中文".encode(), "4S4K3ZUWQ4======"),
|
||||||
(b"中文", "4S4K3ZUWQ4======"), # noqa: E999
|
("中文1".encode(), "4S4K3ZUWQ4YQ===="),
|
||||||
(b"中文1", "4S4K3ZUWQ4YQ===="), # noqa: E999
|
("中文12".encode(), "4S4K3ZUWQ4YTE==="),
|
||||||
(b"中文12", "4S4K3ZUWQ4YTE==="), # noqa: E999
|
("aécio".encode(), "MHB2SY3JN4======"),
|
||||||
(b"aécio", "MHB2SY3JN4======"), # noqa: E999
|
("𠜎".encode(), "6CQJZDQ="),
|
||||||
(b"𠜎", "6CQJZDQ="), # noqa: E999
|
("Base64是一種基於64個可列印字元來表示二進制資料的表示方法".encode(),
|
||||||
(b"Base64是一種基於64個可列印字元來表示二進制資料的表示方法", # noqa: E999
|
|
||||||
"IJQXGZJWGTTJRL7EXCAOPKFO4WP3VZUWXQ3DJZMARPSY7L7FRCL6LDNQ4WWZPZMFQPSL5BXIUGUOPJF24S5IZ2MAWLSYRNXIWOD6NFUZ46NIJ2FBVDT2JOXGS246NM4V"),
|
"IJQXGZJWGTTJRL7EXCAOPKFO4WP3VZUWXQ3DJZMARPSY7L7FRCL6LDNQ4WWZPZMFQPSL5BXIUGUOPJF24S5IZ2MAWLSYRNXIWOD6NFUZ46NIJ2FBVDT2JOXGS246NM4V"),
|
||||||
# fmt: on
|
|
||||||
]
|
]
|
||||||
|
|
||||||
def test_encode(self):
|
def test_encode(self):
|
||||||
|
@ -1,6 +1,3 @@
|
|||||||
# flake8: noqa: F403,F405
|
|
||||||
from common import * # isort:skip
|
|
||||||
|
|
||||||
# Copyright (c) 2017, 2020 Pieter Wuille
|
# Copyright (c) 2017, 2020 Pieter Wuille
|
||||||
#
|
#
|
||||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
@ -21,9 +18,11 @@ from common import * # isort:skip
|
|||||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
# THE SOFTWARE.
|
# THE SOFTWARE.
|
||||||
|
|
||||||
|
|
||||||
"""Reference tests for segwit adresses"""
|
"""Reference tests for segwit adresses"""
|
||||||
|
|
||||||
|
# flake8: noqa: F403,F405
|
||||||
|
from common import * # isort:skip
|
||||||
|
|
||||||
from trezor.crypto import bech32
|
from trezor.crypto import bech32
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,6 +1,3 @@
|
|||||||
# flake8: noqa: F403,F405
|
|
||||||
from common import * # isort:skip
|
|
||||||
|
|
||||||
# Copyright (c) 2017 Pieter Wuille
|
# Copyright (c) 2017 Pieter Wuille
|
||||||
# Copyright (c) 2018 Pavol Rusnak
|
# Copyright (c) 2018 Pavol Rusnak
|
||||||
#
|
#
|
||||||
@ -22,9 +19,11 @@ from common import * # isort:skip
|
|||||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
# THE SOFTWARE.
|
# THE SOFTWARE.
|
||||||
|
|
||||||
|
|
||||||
"""Reference tests for cashaddr adresses"""
|
"""Reference tests for cashaddr adresses"""
|
||||||
|
|
||||||
|
# flake8: noqa: F403,F405
|
||||||
|
from common import * # isort:skip
|
||||||
|
|
||||||
from trezor.crypto import base58, cashaddr
|
from trezor.crypto import base58, cashaddr
|
||||||
|
|
||||||
VALID_CHECKSUM = [
|
VALID_CHECKSUM = [
|
||||||
|
@ -63,7 +63,7 @@ class TestCryptoEd25519(unittest.TestCase):
|
|||||||
self.assertEqual(sig2, unhexlify(sig))
|
self.assertEqual(sig2, unhexlify(sig))
|
||||||
|
|
||||||
def test_verify(self):
|
def test_verify(self):
|
||||||
for sk, pk, sig in self.vectors:
|
for _, pk, sig in self.vectors:
|
||||||
# msg = pk
|
# msg = pk
|
||||||
self.assertTrue(
|
self.assertTrue(
|
||||||
ed25519.verify(unhexlify(pk), unhexlify(sig), unhexlify(pk))
|
ed25519.verify(unhexlify(pk), unhexlify(sig), unhexlify(pk))
|
||||||
|
@ -63,12 +63,10 @@ class TestCryptoGroestl512(unittest.TestCase):
|
|||||||
self.assertEqual(x.digest(), unhexlify(d))
|
self.assertEqual(x.digest(), unhexlify(d))
|
||||||
|
|
||||||
# Test from ExtremelyLongMsgKAT_512.txt, disabled by default because it resource-expensive
|
# Test from ExtremelyLongMsgKAT_512.txt, disabled by default because it resource-expensive
|
||||||
"""
|
# x = hashlib.groestl512()
|
||||||
x = hashlib.groestl512()
|
# for i in range(16777216):
|
||||||
for i in range(16777216):
|
# x.update(b'abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmno')
|
||||||
x.update(b'abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmno')
|
# self.assertEqual(x.digest(), unhexlify('787C88460E5D09ABD7A98C050F3422BBFDBD36A74B05DE04B57A13FA3F36A570B8561580AB9DA4096CCD5111B5DE948F769D9D61833A6CE2B2F223061E688994'))
|
||||||
self.assertEqual(x.digest(), unhexlify('787C88460E5D09ABD7A98C050F3422BBFDBD36A74B05DE04B57A13FA3F36A570B8561580AB9DA4096CCD5111B5DE948F769D9D61833A6CE2B2F223061E688994'))
|
|
||||||
"""
|
|
||||||
|
|
||||||
def test_digest_multi(self):
|
def test_digest_multi(self):
|
||||||
x = hashlib.groestl512()
|
x = hashlib.groestl512()
|
||||||
|
@ -38,7 +38,7 @@ class TestCryptoRipemd160(unittest.TestCase):
|
|||||||
self.assertEqual(x.digest(), unhexlify(d))
|
self.assertEqual(x.digest(), unhexlify(d))
|
||||||
|
|
||||||
x = hashlib.ripemd160()
|
x = hashlib.ripemd160()
|
||||||
for i in range(8):
|
for _ in range(8):
|
||||||
x.update(b"1234567890")
|
x.update(b"1234567890")
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
x.digest(), unhexlify("9b752e45573d4b39f4dbd3323cab82bf63326bfb")
|
x.digest(), unhexlify("9b752e45573d4b39f4dbd3323cab82bf63326bfb")
|
||||||
|
@ -31,18 +31,16 @@ class TestCryptoSha1(unittest.TestCase):
|
|||||||
self.assertEqual(x.digest(), unhexlify(d))
|
self.assertEqual(x.digest(), unhexlify(d))
|
||||||
|
|
||||||
x = hashlib.sha1()
|
x = hashlib.sha1()
|
||||||
for i in range(1000000):
|
for _ in range(1000000):
|
||||||
x.update(b"a")
|
x.update(b"a")
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
x.digest(), unhexlify("34aa973cd4c4daa4f61eeb2bdbad27316534016f")
|
x.digest(), unhexlify("34aa973cd4c4daa4f61eeb2bdbad27316534016f")
|
||||||
)
|
)
|
||||||
|
|
||||||
"""
|
# x = hashlib.sha1()
|
||||||
x = hashlib.sha1()
|
# for i in range(16777216):
|
||||||
for i in range(16777216):
|
# x.update(b'abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmno')
|
||||||
x.update(b'abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmno')
|
# self.assertEqual(x.digest(), unhexlify('7789f0c9ef7bfc40d93311143dfbe69e2017f592'))
|
||||||
self.assertEqual(x.digest(), unhexlify('7789f0c9ef7bfc40d93311143dfbe69e2017f592'))
|
|
||||||
"""
|
|
||||||
|
|
||||||
def test_digest_multi(self):
|
def test_digest_multi(self):
|
||||||
x = hashlib.sha1()
|
x = hashlib.sha1()
|
||||||
|
@ -31,7 +31,7 @@ class TestCryptoSha256(unittest.TestCase):
|
|||||||
self.assertEqual(x.digest(), unhexlify(d))
|
self.assertEqual(x.digest(), unhexlify(d))
|
||||||
|
|
||||||
x = hashlib.sha256()
|
x = hashlib.sha256()
|
||||||
for i in range(1000000):
|
for _ in range(1000000):
|
||||||
x.update(b"a")
|
x.update(b"a")
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
x.digest(),
|
x.digest(),
|
||||||
@ -40,12 +40,10 @@ class TestCryptoSha256(unittest.TestCase):
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
"""
|
# x = hashlib.sha256()
|
||||||
x = hashlib.sha256()
|
# for i in range(16777216):
|
||||||
for i in range(16777216):
|
# x.update(b'abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmno')
|
||||||
x.update(b'abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmno')
|
# self.assertEqual(x.digest(), unhexlify('50e72a0e26442fe2552dc3938ac58658228c0cbfb1d2ca872ae435266fcd055e'))
|
||||||
self.assertEqual(x.digest(), unhexlify('50e72a0e26442fe2552dc3938ac58658228c0cbfb1d2ca872ae435266fcd055e'))
|
|
||||||
"""
|
|
||||||
|
|
||||||
def test_digest_multi(self):
|
def test_digest_multi(self):
|
||||||
x = hashlib.sha256()
|
x = hashlib.sha256()
|
||||||
|
@ -48,7 +48,7 @@ class TestCryptoSha3_256(unittest.TestCase):
|
|||||||
self.assertEqual(x.digest(), unhexlify(d))
|
self.assertEqual(x.digest(), unhexlify(d))
|
||||||
|
|
||||||
x = hashlib.sha3_256()
|
x = hashlib.sha3_256()
|
||||||
for i in range(1000000):
|
for _ in range(1000000):
|
||||||
x.update(b"a")
|
x.update(b"a")
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
x.digest(),
|
x.digest(),
|
||||||
@ -57,12 +57,10 @@ class TestCryptoSha3_256(unittest.TestCase):
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
"""
|
# x = hashlib.sha3_256()
|
||||||
x = hashlib.sha3_256()
|
# for i in range(16777216):
|
||||||
for i in range(16777216):
|
# x.update(b'abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmno')
|
||||||
x.update(b'abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmno')
|
# self.assertEqual(x.digest(), unhexlify('ecbbc42cbf296603acb2c6bc0410ef4378bafb24b710357f12df607758b33e2b'))
|
||||||
self.assertEqual(x.digest(), unhexlify('ecbbc42cbf296603acb2c6bc0410ef4378bafb24b710357f12df607758b33e2b'))
|
|
||||||
"""
|
|
||||||
|
|
||||||
def test_update_keccak(self):
|
def test_update_keccak(self):
|
||||||
for b, d in self.vectors_keccak:
|
for b, d in self.vectors_keccak:
|
||||||
|
@ -60,7 +60,7 @@ class TestCryptoSha3_512(unittest.TestCase):
|
|||||||
self.assertEqual(x.digest(), unhexlify(d))
|
self.assertEqual(x.digest(), unhexlify(d))
|
||||||
|
|
||||||
x = hashlib.sha3_512()
|
x = hashlib.sha3_512()
|
||||||
for i in range(1000000):
|
for _ in range(1000000):
|
||||||
x.update(b"a")
|
x.update(b"a")
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
x.digest(),
|
x.digest(),
|
||||||
@ -69,12 +69,10 @@ class TestCryptoSha3_512(unittest.TestCase):
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
"""
|
# x = hashlib.sha3_512()
|
||||||
x = hashlib.sha3_512()
|
# for i in range(16777216):
|
||||||
for i in range(16777216):
|
# x.update(b'abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmno')
|
||||||
x.update(b'abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmno')
|
# self.assertEqual(x.digest(), unhexlify('235ffd53504ef836a1342b488f483b396eabbfe642cf78ee0d31feec788b23d0d18d5c339550dd5958a500d4b95363da1b5fa18affc1bab2292dc63b7d85097c'))
|
||||||
self.assertEqual(x.digest(), unhexlify('235ffd53504ef836a1342b488f483b396eabbfe642cf78ee0d31feec788b23d0d18d5c339550dd5958a500d4b95363da1b5fa18affc1bab2292dc63b7d85097c'))
|
|
||||||
"""
|
|
||||||
|
|
||||||
def test_update_keccak(self):
|
def test_update_keccak(self):
|
||||||
for b, d in self.vectors_keccak:
|
for b, d in self.vectors_keccak:
|
||||||
|
@ -37,7 +37,7 @@ class TestCryptoSha512(unittest.TestCase):
|
|||||||
self.assertEqual(x.digest(), unhexlify(d))
|
self.assertEqual(x.digest(), unhexlify(d))
|
||||||
|
|
||||||
x = hashlib.sha512()
|
x = hashlib.sha512()
|
||||||
for i in range(1000000):
|
for _ in range(1000000):
|
||||||
x.update(b"a")
|
x.update(b"a")
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
x.digest(),
|
x.digest(),
|
||||||
@ -46,12 +46,10 @@ class TestCryptoSha512(unittest.TestCase):
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
"""
|
# x = hashlib.sha512()
|
||||||
x = hashlib.sha512()
|
# for i in range(16777216):
|
||||||
for i in range(16777216):
|
# x.update(b'abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmno')
|
||||||
x.update(b'abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmno')
|
# self.assertEqual(x.digest(), unhexlify('b47c933421ea2db149ad6e10fce6c7f93d0752380180ffd7f4629a712134831d77be6091b819ed352c2967a2e2d4fa5050723c9630691f1a05a7281dbe6c1086'))
|
||||||
self.assertEqual(x.digest(), unhexlify('b47c933421ea2db149ad6e10fce6c7f93d0752380180ffd7f4629a712134831d77be6091b819ed352c2967a2e2d4fa5050723c9630691f1a05a7281dbe6c1086'))
|
|
||||||
"""
|
|
||||||
|
|
||||||
def test_digest_multi(self):
|
def test_digest_multi(self):
|
||||||
x = hashlib.sha512()
|
x = hashlib.sha512()
|
||||||
|
@ -111,7 +111,7 @@ class TestCryptoHmac(unittest.TestCase):
|
|||||||
# case 3
|
# case 3
|
||||||
key = b"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
|
key = b"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
|
||||||
x = hmac(hmac.SHA256, key)
|
x = hmac(hmac.SHA256, key)
|
||||||
for i in range(50):
|
for _ in range(50):
|
||||||
x.update(b"\xdd")
|
x.update(b"\xdd")
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
x.digest(),
|
x.digest(),
|
||||||
@ -120,7 +120,7 @@ class TestCryptoHmac(unittest.TestCase):
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
x = hmac(hmac.SHA512, key)
|
x = hmac(hmac.SHA512, key)
|
||||||
for i in range(50):
|
for _ in range(50):
|
||||||
x.update(b"\xdd")
|
x.update(b"\xdd")
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
x.digest(),
|
x.digest(),
|
||||||
@ -132,7 +132,7 @@ class TestCryptoHmac(unittest.TestCase):
|
|||||||
# case 4
|
# case 4
|
||||||
key = b"\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19"
|
key = b"\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19"
|
||||||
x = hmac(hmac.SHA256, key)
|
x = hmac(hmac.SHA256, key)
|
||||||
for i in range(50):
|
for _ in range(50):
|
||||||
x.update(b"\xcd")
|
x.update(b"\xcd")
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
x.digest(),
|
x.digest(),
|
||||||
@ -141,7 +141,7 @@ class TestCryptoHmac(unittest.TestCase):
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
x = hmac(hmac.SHA512, key)
|
x = hmac(hmac.SHA512, key)
|
||||||
for i in range(50):
|
for _ in range(50):
|
||||||
x.update(b"\xcd")
|
x.update(b"\xcd")
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
x.digest(),
|
x.digest(),
|
||||||
|
@ -65,7 +65,7 @@ class TestCryptoPbkdf2(unittest.TestCase):
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
p = pbkdf2(pbkdf2.HMAC_SHA256, P, S)
|
p = pbkdf2(pbkdf2.HMAC_SHA256, P, S)
|
||||||
for i in range(32):
|
for _ in range(32):
|
||||||
p.update(128)
|
p.update(128)
|
||||||
dk = p.key()
|
dk = p.key()
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
@ -77,7 +77,7 @@ class TestCryptoPbkdf2(unittest.TestCase):
|
|||||||
P = b"passwordPASSWORDpassword"
|
P = b"passwordPASSWORDpassword"
|
||||||
S = b"saltSALTsaltSALTsaltSALTsaltSALTsalt"
|
S = b"saltSALTsaltSALTsaltSALTsaltSALTsalt"
|
||||||
p = pbkdf2(pbkdf2.HMAC_SHA256, P, S)
|
p = pbkdf2(pbkdf2.HMAC_SHA256, P, S)
|
||||||
for i in range(64):
|
for _ in range(64):
|
||||||
p.update(64)
|
p.update(64)
|
||||||
dk = p.key()
|
dk = p.key()
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
@ -146,7 +146,7 @@ class TestCryptoPbkdf2(unittest.TestCase):
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
p = pbkdf2(pbkdf2.HMAC_SHA512, P, S)
|
p = pbkdf2(pbkdf2.HMAC_SHA512, P, S)
|
||||||
for i in range(32):
|
for _ in range(32):
|
||||||
p.update(128)
|
p.update(128)
|
||||||
dk = p.key()
|
dk = p.key()
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
@ -158,7 +158,7 @@ class TestCryptoPbkdf2(unittest.TestCase):
|
|||||||
P = b"passwordPASSWORDpassword"
|
P = b"passwordPASSWORDpassword"
|
||||||
S = b"saltSALTsaltSALTsaltSALTsaltSALTsalt"
|
S = b"saltSALTsaltSALTsaltSALTsaltSALTsalt"
|
||||||
p = pbkdf2(pbkdf2.HMAC_SHA512, P, S)
|
p = pbkdf2(pbkdf2.HMAC_SHA512, P, S)
|
||||||
for i in range(64):
|
for _ in range(64):
|
||||||
p.update(64)
|
p.update(64)
|
||||||
dk = p.key()
|
dk = p.key()
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
|
@ -65,13 +65,13 @@ class TestCryptoSlip39(unittest.TestCase):
|
|||||||
identifier = slip39.generate_random_identifier()
|
identifier = slip39.generate_random_identifier()
|
||||||
mnemonics = slip39.split_ems(1, [(3, 5)], identifier, extendable, 1, self.EMS)
|
mnemonics = slip39.split_ems(1, [(3, 5)], identifier, extendable, 1, self.EMS)
|
||||||
mnemonics = mnemonics[0]
|
mnemonics = mnemonics[0]
|
||||||
identifier, extendable, exponent, ems = slip39.recover_ems(mnemonics[1:4])
|
identifier, extendable, _, ems = slip39.recover_ems(mnemonics[1:4])
|
||||||
self.assertEqual(ems, self.EMS)
|
self.assertEqual(ems, self.EMS)
|
||||||
|
|
||||||
identifier = slip39.generate_random_identifier()
|
identifier = slip39.generate_random_identifier()
|
||||||
mnemonics = slip39.split_ems(1, [(3, 5)], identifier, extendable, 2, self.EMS)
|
mnemonics = slip39.split_ems(1, [(3, 5)], identifier, extendable, 2, self.EMS)
|
||||||
mnemonics = mnemonics[0]
|
mnemonics = mnemonics[0]
|
||||||
identifier, extendable, exponent, ems = slip39.recover_ems(mnemonics[1:4])
|
identifier, extendable, _, ems = slip39.recover_ems(mnemonics[1:4])
|
||||||
self.assertEqual(ems, self.EMS)
|
self.assertEqual(ems, self.EMS)
|
||||||
|
|
||||||
def test_group_sharing(self):
|
def test_group_sharing(self):
|
||||||
|
@ -54,7 +54,10 @@ class TestUtils(unittest.TestCase):
|
|||||||
) # b'\xe1\x88\xb4\xe5\x99\xb8
|
) # b'\xe1\x88\xb4\xe5\x99\xb8
|
||||||
|
|
||||||
def test_firmware_hash(self):
|
def test_firmware_hash(self):
|
||||||
if utils.INTERNAL_MODEL in ('DISC2', 'T3W1'):
|
if utils.INTERNAL_MODEL in ( # pylint: disable=internal-model-tuple-comparison
|
||||||
|
"DISC2",
|
||||||
|
"T3W1",
|
||||||
|
):
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
utils.firmware_hash(),
|
utils.firmware_hash(),
|
||||||
b"\xde\xce\xc5\xf6\xa4vgl5\x13l2\xa5\xf8F\xd8\xba\n$\x0b!x\x1fVM\x1e\xf3}@\xd9\xa8\xe9",
|
b"\xde\xce\xc5\xf6\xa4vgl5\x13l2\xa5\xf8F\xd8\xba\n$\x0b!x\x1fVM\x1e\xf3}@\xd9\xa8\xe9",
|
||||||
|
@ -140,10 +140,11 @@ class TestCase:
|
|||||||
func(*args, **kwargs)
|
func(*args, **kwargs)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if isinstance(e, exc):
|
if isinstance(e, exc):
|
||||||
return
|
return None
|
||||||
raise
|
raise
|
||||||
else:
|
else:
|
||||||
ensure(False, f"{repr(exc)} not raised")
|
ensure(False, f"{repr(exc)} not raised")
|
||||||
|
return None
|
||||||
|
|
||||||
def assertListEqual(self, x, y, msg=""):
|
def assertListEqual(self, x, y, msg=""):
|
||||||
if len(x) != len(y):
|
if len(x) != len(y):
|
||||||
|
Loading…
Reference in New Issue
Block a user