fix to pass tests.py

* deterministic_keys() now accepts both str and bytes for passphrase.

* The test for RandomTrackingDict is modified to use bytes
 for random keys.
This commit is contained in:
Kashiko Koibumi 2024-05-18 12:13:24 +09:00
parent bc254a935e
commit 3f808fbcd7
No known key found for this signature in database
GPG Key ID: 8F06E069E37C40C4
2 changed files with 10 additions and 5 deletions

View File

@ -85,7 +85,12 @@ def random_keys():
def deterministic_keys(passphrase, nonce):
"""Generate keys from *passphrase* and *nonce* (encoded as varint)"""
priv = hashlib.sha512(passphrase.encode() + nonce).digest()[:32]
if isinstance(passphrase, str):
ph = passphrase.encode()
else:
ph = passphrase
priv = hashlib.sha512(ph + nonce).digest()[:32]
pub = pointMult(priv)
return priv, pub

View File

@ -15,10 +15,10 @@ class TestRandomTrackingDict(unittest.TestCase):
@staticmethod
def randString():
"""helper function for tests, generates a random string"""
retval = ''
for _ in range(32):
retval += chr(random.randint(0, 255))
return retval
retval = bytearray(32)
for i in range(32):
retval[i] = random.randint(0, 255)
return bytes(retval)
def test_check_randomtrackingdict(self):
"""Check the logic of RandomTrackingDict class"""