From 44f402c64e3b62473ca77f87d4b5a1fe59d1c3da Mon Sep 17 00:00:00 2001 From: Victor Shyba Date: Fri, 3 Jan 2020 01:44:41 -0300 Subject: [PATCH] delete cryptoutils --- lbry/blob/__init__.py | 2 +- lbry/blob/blob_file.py | 4 +++- lbry/blob/writer.py | 2 +- lbry/cryptoutils.py | 9 --------- lbry/stream/descriptor.py | 2 +- lbry/utils.py | 6 +++++- 6 files changed, 11 insertions(+), 14 deletions(-) delete mode 100644 lbry/cryptoutils.py diff --git a/lbry/blob/__init__.py b/lbry/blob/__init__.py index e2fcdfd70..de7b7b2b0 100644 --- a/lbry/blob/__init__.py +++ b/lbry/blob/__init__.py @@ -1,4 +1,4 @@ -from lbry.cryptoutils import get_lbry_hash_obj +from lbry.utils import get_lbry_hash_obj MAX_BLOB_SIZE = 2 * 2 ** 20 diff --git a/lbry/blob/blob_file.py b/lbry/blob/blob_file.py index 0492a3844..9a2e3e680 100644 --- a/lbry/blob/blob_file.py +++ b/lbry/blob/blob_file.py @@ -9,8 +9,9 @@ from io import BytesIO from cryptography.hazmat.primitives.ciphers import Cipher, modes from cryptography.hazmat.primitives.ciphers.algorithms import AES from cryptography.hazmat.primitives.padding import PKCS7 +from cryptography.hazmat.backends import default_backend -from lbry.cryptoutils import backend, get_lbry_hash_obj +from lbry.utils import get_lbry_hash_obj from lbry.error import DownloadCancelledError, InvalidBlobHashError, InvalidDataError from lbry.blob import MAX_BLOB_SIZE, blobhash_length @@ -21,6 +22,7 @@ log = logging.getLogger(__name__) _hexmatch = re.compile("^[a-f,0-9]+$") +backend = default_backend() def is_valid_blobhash(blobhash: str) -> bool: diff --git a/lbry/blob/writer.py b/lbry/blob/writer.py index 0f119cdb4..25ae18942 100644 --- a/lbry/blob/writer.py +++ b/lbry/blob/writer.py @@ -3,7 +3,7 @@ import logging import asyncio from io import BytesIO from lbry.error import InvalidBlobHashError, InvalidDataError -from lbry.cryptoutils import get_lbry_hash_obj +from lbry.utils import get_lbry_hash_obj log = logging.getLogger(__name__) diff --git a/lbry/cryptoutils.py b/lbry/cryptoutils.py deleted file mode 100644 index 3c90ee598..000000000 --- a/lbry/cryptoutils.py +++ /dev/null @@ -1,9 +0,0 @@ -import hashlib -from cryptography.hazmat.backends import default_backend - - -backend = default_backend() - - -def get_lbry_hash_obj(): - return hashlib.sha384() diff --git a/lbry/stream/descriptor.py b/lbry/stream/descriptor.py index f44f0d641..70dd95277 100644 --- a/lbry/stream/descriptor.py +++ b/lbry/stream/descriptor.py @@ -10,7 +10,7 @@ from cryptography.hazmat.primitives.ciphers.algorithms import AES from lbry.blob import MAX_BLOB_SIZE from lbry.blob.blob_info import BlobInfo from lbry.blob.blob_file import AbstractBlob, BlobFile -from lbry.cryptoutils import get_lbry_hash_obj +from lbry.utils import get_lbry_hash_obj from lbry.error import InvalidStreamDescriptorError log = logging.getLogger(__name__) diff --git a/lbry/utils.py b/lbry/utils.py index 1c4a89359..7df357b90 100644 --- a/lbry/utils.py +++ b/lbry/utils.py @@ -17,8 +17,8 @@ import pkg_resources import certifi import aiohttp +import hashlib from lbry.schema.claim import Claim -from lbry.cryptoutils import get_lbry_hash_obj log = logging.getLogger(__name__) @@ -49,6 +49,10 @@ def datetime_obj(*args, **kwargs): return datetime.datetime(*args, **kwargs) +def get_lbry_hash_obj(): + return hashlib.sha384() + + def generate_id(num=None): h = get_lbry_hash_obj() if num is not None: