Skip to content

Commit

Permalink
Remove unused function.
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathangreen committed Feb 9, 2024
1 parent ba8de29 commit 5e61f82
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 38 deletions.
11 changes: 0 additions & 11 deletions core/util/string_helpers.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,10 @@
# Helper functions and objects regarding strings -- especially stuff
# that lets us negotiate the distinction between Unicode and
# bytestrings.
import binascii
import os
import secrets
import string


def random_string(size: int) -> str:
"""Generate a random string of binary, encoded as hex digits.
:param: Size of binary string in bytes.
:return: A Unicode string.
"""
return binascii.hexlify(os.urandom(size)).decode("utf8")


def random_key(size: int) -> str:
"""Generate a random string suitable for use as a key.
Expand Down
28 changes: 1 addition & 27 deletions tests/core/util/test_string_helpers.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,8 @@
# Test the helper objects in util.string.

import re
import string

from core.util.string_helpers import random_key, random_string


def test_random_string():
m = random_string
assert "" == m(0)

# The strings are random.
res1 = m(8)
res2 = m(8)
assert res1 != res2

# We can't test exact values, because the randomness comes
# from /dev/urandom, but we can test some of their properties:
for size in range(1, 16):
x = m(size)

# The strings are Unicode strings, not bytestrings
assert isinstance(x, str)

# The strings are entirely composed of lowercase hex digits.
assert None == re.compile("[^a-f0-9]").search(x)

# Each byte is represented as two digits, so the length of the
# string is twice the length passed in to the function.
assert size * 2 == len(x)
from core.util.string_helpers import random_key


def test_random_key():
Expand Down

0 comments on commit 5e61f82

Please sign in to comment.