From 11ffdba3a3e81906e9e61746db45751cfa4e9fdd Mon Sep 17 00:00:00 2001 From: Mawoka Date: Fri, 24 Jun 2022 18:00:36 +0200 Subject: [PATCH] :rotating_light: Fixed linter errors --- classquiz/helpers/__init__.py | 5 ++--- classquiz/helpers/hashcash.py | 13 ++++++------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/classquiz/helpers/__init__.py b/classquiz/helpers/__init__.py index b524905..3de4d69 100644 --- a/classquiz/helpers/__init__.py +++ b/classquiz/helpers/__init__.py @@ -8,7 +8,6 @@ from io import BytesIO from PIL import Image from classquiz.config import meilisearch, settings from classquiz.helpers.hashcash import check as hc_check -from datetime import datetime settings = settings() @@ -123,7 +122,7 @@ def check_hashcash(data: str, input_data: str, claim_in: Optional[str] = "19") - if not hc_check(data): return False try: - version, claim, date, res, ext, rand, counter = data.split(":") + version, claim, _date, res, ext, _rand, _counter = data.split(":") except ValueError: return False try: @@ -132,5 +131,5 @@ def check_hashcash(data: str, input_data: str, claim_in: Optional[str] = "19") - assert res == input_data assert ext == "" return True - except AssertionError as e: + except AssertionError: return False diff --git a/classquiz/helpers/hashcash.py b/classquiz/helpers/hashcash.py index 612a4bb..bf4e9bb 100644 --- a/classquiz/helpers/hashcash.py +++ b/classquiz/helpers/hashcash.py @@ -33,7 +33,6 @@ Notice that '_mint()' behaves deterministically, finding the same suffix every time it is passed the same arguments. 'mint()' incorporates a random salt in stamps (as per the hashcash v.1 protocol). """ -import sys from string import ascii_letters from math import ceil, floor import hashlib @@ -97,7 +96,7 @@ def _mint(challenge, bits): hex_digits = int(ceil(bits / 4.0)) zeros = "0" * hex_digits while 1: - digest = hashlib.sha1((challenge + hex(counter)[2:]).encode()).hexdigest() + digest = hashlib.sha1((challenge + hex(counter)[2:]).encode(), usedforsecurity=False).hexdigest() if digest[:hex_digits] == zeros: tries[0] = counter return hex(counter)[2:] @@ -123,7 +122,7 @@ def check(stamp, resource=None, bits=None, check_expiration=None, ds_callback=No """ if stamp.startswith("0:"): # Version 0 try: - date, res, suffix = stamp[2:].split(":") + date, res, _suffix = stamp[2:].split(":") except ValueError: return False if resource is not None and resource != res: @@ -138,10 +137,10 @@ def check(stamp, resource=None, bits=None, check_expiration=None, ds_callback=No return True else: hex_digits = int(floor(bits / 4)) - return hashlib.sha1((stamp).encode()).hexdigest().startswith("0" * hex_digits) + return hashlib.sha1((stamp).encode(), usedforsecurity=False).hexdigest().startswith("0" * hex_digits) elif stamp.startswith("1:"): # Version 1 try: - claim, date, res, ext, rand, counter = stamp[2:].split(":") + claim, date, res, _ext, _rand, _counter = stamp[2:].split(":") except ValueError: return False if resource is not None and resource != res: @@ -156,7 +155,7 @@ def check(stamp, resource=None, bits=None, check_expiration=None, ds_callback=No return False else: hex_digits = int(floor(int(claim) / 4)) - return hashlib.sha1((stamp).encode()).hexdigest().startswith("0" * hex_digits) + return hashlib.sha1((stamp).encode(), usedforsecurity=False).hexdigest().startswith("0" * hex_digits) else: # Unknown ver or generalized hashcash if type(bits) is not int: return True @@ -164,4 +163,4 @@ def check(stamp, resource=None, bits=None, check_expiration=None, ds_callback=No return False else: hex_digits = int(floor(bits / 4)) - return hashlib.sha1((stamp).encode()).hexdigest().startswith("0" * hex_digits) + return hashlib.sha1((stamp).encode(), usedforsecurity=False).hexdigest().startswith("0" * hex_digits)