faster is_valid_hashcharacter

This commit is contained in:
Jack Robison 2019-02-08 19:57:26 -05:00
parent 45404b6ad4
commit 0c93090d2c
No known key found for this signature in database
GPG key ID: DF25C68FE0239BB2

View file

@ -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()