🚨 Fixed linter errors

This commit is contained in:
Mawoka
2022-06-24 18:00:36 +02:00
parent 1cea8860cc
commit 11ffdba3a3
2 changed files with 8 additions and 10 deletions
+2 -3
View File
@@ -8,7 +8,6 @@ from io import BytesIO
from PIL import Image from PIL import Image
from classquiz.config import meilisearch, settings from classquiz.config import meilisearch, settings
from classquiz.helpers.hashcash import check as hc_check from classquiz.helpers.hashcash import check as hc_check
from datetime import datetime
settings = settings() settings = settings()
@@ -123,7 +122,7 @@ def check_hashcash(data: str, input_data: str, claim_in: Optional[str] = "19") -
if not hc_check(data): if not hc_check(data):
return False return False
try: try:
version, claim, date, res, ext, rand, counter = data.split(":") version, claim, _date, res, ext, _rand, _counter = data.split(":")
except ValueError: except ValueError:
return False return False
try: try:
@@ -132,5 +131,5 @@ def check_hashcash(data: str, input_data: str, claim_in: Optional[str] = "19") -
assert res == input_data assert res == input_data
assert ext == "" assert ext == ""
return True return True
except AssertionError as e: except AssertionError:
return False return False
+6 -7
View File
@@ -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 every time it is passed the same arguments. 'mint()' incorporates a random
salt in stamps (as per the hashcash v.1 protocol). salt in stamps (as per the hashcash v.1 protocol).
""" """
import sys
from string import ascii_letters from string import ascii_letters
from math import ceil, floor from math import ceil, floor
import hashlib import hashlib
@@ -97,7 +96,7 @@ def _mint(challenge, bits):
hex_digits = int(ceil(bits / 4.0)) hex_digits = int(ceil(bits / 4.0))
zeros = "0" * hex_digits zeros = "0" * hex_digits
while 1: 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: if digest[:hex_digits] == zeros:
tries[0] = counter tries[0] = counter
return hex(counter)[2:] 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 if stamp.startswith("0:"): # Version 0
try: try:
date, res, suffix = stamp[2:].split(":") date, res, _suffix = stamp[2:].split(":")
except ValueError: except ValueError:
return False return False
if resource is not None and resource != res: 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 return True
else: else:
hex_digits = int(floor(bits / 4)) 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 elif stamp.startswith("1:"): # Version 1
try: try:
claim, date, res, ext, rand, counter = stamp[2:].split(":") claim, date, res, _ext, _rand, _counter = stamp[2:].split(":")
except ValueError: except ValueError:
return False return False
if resource is not None and resource != res: 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 return False
else: else:
hex_digits = int(floor(int(claim) / 4)) 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 else: # Unknown ver or generalized hashcash
if type(bits) is not int: if type(bits) is not int:
return True return True
@@ -164,4 +163,4 @@ def check(stamp, resource=None, bits=None, check_expiration=None, ds_callback=No
return False return False
else: else:
hex_digits = int(floor(bits / 4)) 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)