forked from LBRYCommunity/lbry-sdk
faster is_valid_blobhash
This commit is contained in:
parent
aeb2891baa
commit
45404b6ad4
1 changed files with 5 additions and 2 deletions
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue