Skip to content

Commit

Permalink
handled empty BinStr entropy
Browse files Browse the repository at this point in the history
  • Loading branch information
fametrano committed May 21, 2020
1 parent 1d7db03 commit 528d415
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion btclib/entropy.py
Expand Up @@ -292,7 +292,7 @@ def randbinstr(
- possibly hashed (if requested)
"""

if entropy is None:
if entropy is None or entropy == "":
i = secrets.randbits(bits)
else:
if len(entropy) > bits:
Expand Down
6 changes: 6 additions & 0 deletions btclib/tests/test_entropy.py
Expand Up @@ -239,9 +239,15 @@ def test_randbinstr():
bits = 256
binstr = randbinstr(bits, hash=hash)
assert len(binstr) == bits
binstr2 = randbinstr(bits, "", hash=hash)
assert len(binstr2) == bits
assert binstr != binstr2
binstr2 = randbinstr(bits, hash=hash)
assert len(binstr2) == bits
assert binstr != binstr2
binstr2 = randbinstr(bits, "", hash=hash)
assert len(binstr2) == bits
assert binstr != binstr2

bits = 512
binstr = randbinstr(bits, hash=hash)
Expand Down

0 comments on commit 528d415

Please sign in to comment.