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:
parent
bc254a935e
commit
3f808fbcd7
|
@ -85,7 +85,12 @@ def random_keys():
|
||||||
|
|
||||||
def deterministic_keys(passphrase, nonce):
|
def deterministic_keys(passphrase, nonce):
|
||||||
"""Generate keys from *passphrase* and *nonce* (encoded as varint)"""
|
"""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)
|
pub = pointMult(priv)
|
||||||
return priv, pub
|
return priv, pub
|
||||||
|
|
||||||
|
|
|
@ -15,10 +15,10 @@ class TestRandomTrackingDict(unittest.TestCase):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def randString():
|
def randString():
|
||||||
"""helper function for tests, generates a random string"""
|
"""helper function for tests, generates a random string"""
|
||||||
retval = ''
|
retval = bytearray(32)
|
||||||
for _ in range(32):
|
for i in range(32):
|
||||||
retval += chr(random.randint(0, 255))
|
retval[i] = random.randint(0, 255)
|
||||||
return retval
|
return bytes(retval)
|
||||||
|
|
||||||
def test_check_randomtrackingdict(self):
|
def test_check_randomtrackingdict(self):
|
||||||
"""Check the logic of RandomTrackingDict class"""
|
"""Check the logic of RandomTrackingDict class"""
|
||||||
|
|
Reference in New Issue
Block a user