From 0c93090d2ce6877f0d7537739f1911dea7d51b35 Mon Sep 17 00:00:00 2001 From: Jack Robison Date: Fri, 8 Feb 2019 19:57:26 -0500 Subject: [PATCH] faster is_valid_hashcharacter --- lbrynet/blob/blob_file.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lbrynet/blob/blob_file.py b/lbrynet/blob/blob_file.py index 69790f261..f99dbe768 100644 --- a/lbrynet/blob/blob_file.py +++ b/lbrynet/blob/blob_file.py @@ -18,13 +18,13 @@ from lbrynet.blob.writer import HashBlobWriter log = logging.getLogger(__name__) -def is_valid_hashcharacter(char: str) -> bool: - return char in "0123456789abcdef" - - _hexmatch = re.compile("^[a-f,0-9]+$") +def is_valid_hashcharacter(char: str) -> bool: + return len(char) == 1 and _hexmatch.match(char) + + def is_valid_blobhash(blobhash: str) -> bool: """Checks whether the blobhash is the correct length and contains only valid characters (0-9, a-f) @@ -35,6 +35,7 @@ def is_valid_blobhash(blobhash: str) -> bool: """ return len(blobhash) == blobhash_length and _hexmatch.match(blobhash) + def encrypt_blob_bytes(key: bytes, iv: bytes, unencrypted: bytes) -> typing.Tuple[bytes, str]: cipher = Cipher(AES(key), modes.CBC(iv), backend=backend) padder = PKCS7(AES.block_size).padder()