diff --git a/lbrynet/blob/blob_file.py b/lbrynet/blob/blob_file.py index 9d6246d09..69790f261 100644 --- a/lbrynet/blob/blob_file.py +++ b/lbrynet/blob/blob_file.py @@ -1,4 +1,5 @@ import os +import re import asyncio import binascii import logging @@ -21,6 +22,9 @@ def is_valid_hashcharacter(char: str) -> bool: return char in "0123456789abcdef" +_hexmatch = re.compile("^[a-f,0-9]+$") + + def is_valid_blobhash(blobhash: str) -> bool: """Checks whether the blobhash is the correct length and contains only valid characters (0-9, a-f) @@ -29,8 +33,7 @@ def is_valid_blobhash(blobhash: str) -> bool: @return: True/False """ - return len(blobhash) == blobhash_length and all(is_valid_hashcharacter(l) for l in blobhash) - + 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)