lint blob/*

This commit is contained in:
Victor Shyba 2020-01-03 02:57:36 -03:00 committed by Lex Berezhny
parent d27e8cf73a
commit 867478697d
2 changed files with 8 additions and 8 deletions

View file

@ -3,4 +3,4 @@ from lbry.utils import get_lbry_hash_obj
MAX_BLOB_SIZE = 2 * 2 ** 20 MAX_BLOB_SIZE = 2 * 2 ** 20
# digest_size is in bytes, and blob hashes are hex encoded # digest_size is in bytes, and blob hashes are hex encoded
blobhash_length = get_lbry_hash_obj().digest_size * 2 BLOBHASH_LENGTH = get_lbry_hash_obj().digest_size * 2

View file

@ -14,15 +14,15 @@ from cryptography.hazmat.backends import default_backend
from lbry.utils import get_lbry_hash_obj from lbry.utils import get_lbry_hash_obj
from lbry.error import DownloadCancelledError, InvalidBlobHashError, InvalidDataError from lbry.error import DownloadCancelledError, InvalidBlobHashError, InvalidDataError
from lbry.blob import MAX_BLOB_SIZE, blobhash_length from lbry.blob import MAX_BLOB_SIZE, BLOBHASH_LENGTH
from lbry.blob.blob_info import BlobInfo from lbry.blob.blob_info import BlobInfo
from lbry.blob.writer import HashBlobWriter from lbry.blob.writer import HashBlobWriter
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
_hexmatch = re.compile("^[a-f,0-9]+$") HEXMATCH = re.compile("^[a-f,0-9]+$")
backend = default_backend() BACKEND = default_backend()
def is_valid_blobhash(blobhash: str) -> bool: def is_valid_blobhash(blobhash: str) -> bool:
@ -33,11 +33,11 @@ def is_valid_blobhash(blobhash: str) -> bool:
@return: True/False @return: True/False
""" """
return len(blobhash) == blobhash_length and _hexmatch.match(blobhash) return len(blobhash) == BLOBHASH_LENGTH and HEXMATCH.match(blobhash)
def encrypt_blob_bytes(key: bytes, iv: bytes, unencrypted: bytes) -> typing.Tuple[bytes, str]: def encrypt_blob_bytes(key: bytes, iv: bytes, unencrypted: bytes) -> typing.Tuple[bytes, str]:
cipher = Cipher(AES(key), modes.CBC(iv), backend=backend) cipher = Cipher(AES(key), modes.CBC(iv), backend=BACKEND)
padder = PKCS7(AES.block_size).padder() padder = PKCS7(AES.block_size).padder()
encryptor = cipher.encryptor() encryptor = cipher.encryptor()
encrypted = encryptor.update(padder.update(unencrypted) + padder.finalize()) + encryptor.finalize() encrypted = encryptor.update(padder.update(unencrypted) + padder.finalize()) + encryptor.finalize()
@ -49,7 +49,7 @@ def encrypt_blob_bytes(key: bytes, iv: bytes, unencrypted: bytes) -> typing.Tupl
def decrypt_blob_bytes(data: bytes, length: int, key: bytes, iv: bytes) -> bytes: def decrypt_blob_bytes(data: bytes, length: int, key: bytes, iv: bytes) -> bytes:
if len(data) != length: if len(data) != length:
raise ValueError("unexpected length") raise ValueError("unexpected length")
cipher = Cipher(AES(key), modes.CBC(iv), backend=backend) cipher = Cipher(AES(key), modes.CBC(iv), backend=BACKEND)
unpadder = PKCS7(AES.block_size).unpadder() unpadder = PKCS7(AES.block_size).unpadder()
decryptor = cipher.decryptor() decryptor = cipher.decryptor()
return unpadder.update(decryptor.update(data) + decryptor.finalize()) + unpadder.finalize() return unpadder.update(decryptor.update(data) + decryptor.finalize()) + unpadder.finalize()
@ -144,7 +144,7 @@ class AbstractBlob:
def close(self): def close(self):
while self.writers: while self.writers:
peer, writer = self.writers.popitem() _, writer = self.writers.popitem()
if writer and writer.finished and not writer.finished.done() and not self.loop.is_closed(): if writer and writer.finished and not writer.finished.done() and not self.loop.is_closed():
writer.finished.cancel() writer.finished.cancel()
while self.readers: while self.readers: