diff options
| author | django-bot <ops@djangoproject.com> | 2022-02-03 20:24:19 +0100 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2022-02-07 20:37:05 +0100 |
| commit | 9c19aff7c7561e3a82978a272ecdaad40dda5c00 (patch) | |
| tree | f0506b668a013d0063e5fba3dbf4863b466713ba /django/utils/crypto.py | |
| parent | f68fa8b45dfac545cfc4111d4e52804c86db68d3 (diff) | |
Refs #33476 -- Reformatted code with Black.
Diffstat (limited to 'django/utils/crypto.py')
| -rw-r--r-- | django/utils/crypto.py | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/django/utils/crypto.py b/django/utils/crypto.py index 2af58fda6e..341cb742c1 100644 --- a/django/utils/crypto.py +++ b/django/utils/crypto.py @@ -12,10 +12,11 @@ from django.utils.inspect import func_supports_parameter class InvalidAlgorithm(ValueError): """Algorithm is not supported by hashlib.""" + pass -def salted_hmac(key_salt, value, secret=None, *, algorithm='sha1'): +def salted_hmac(key_salt, value, secret=None, *, algorithm="sha1"): """ Return the HMAC of 'value', using a key generated from key_salt and a secret (which defaults to settings.SECRET_KEY). Default algorithm is SHA1, @@ -32,8 +33,7 @@ def salted_hmac(key_salt, value, secret=None, *, algorithm='sha1'): hasher = getattr(hashlib, algorithm) except AttributeError as e: raise InvalidAlgorithm( - '%r is not an algorithm accepted by the hashlib module.' - % algorithm + "%r is not an algorithm accepted by the hashlib module." % algorithm ) from e # We need to generate a derived key from our base key. We can do this by # passing the key_salt and our base key through a pseudo-random function. @@ -45,7 +45,7 @@ def salted_hmac(key_salt, value, secret=None, *, algorithm='sha1'): return hmac.new(key, msg=force_bytes(value), digestmod=hasher) -RANDOM_STRING_CHARS = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789' +RANDOM_STRING_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" def get_random_string(length, allowed_chars=RANDOM_STRING_CHARS): @@ -59,7 +59,7 @@ def get_random_string(length, allowed_chars=RANDOM_STRING_CHARS): * length: 12, bit length =~ 71 bits * length: 22, bit length =~ 131 bits """ - return ''.join(secrets.choice(allowed_chars) for i in range(length)) + return "".join(secrets.choice(allowed_chars) for i in range(length)) def constant_time_compare(val1, val2): @@ -81,11 +81,12 @@ def pbkdf2(password, salt, iterations, dklen=0, digest=None): # detect whether the usedforsecurity argument is available as this fix may also # have been applied by downstream package maintainers to other versions in # their repositories. -if func_supports_parameter(hashlib.md5, 'usedforsecurity'): +if func_supports_parameter(hashlib.md5, "usedforsecurity"): md5 = hashlib.md5 new_hash = hashlib.new else: - def md5(data=b'', *, usedforsecurity=True): + + def md5(data=b"", *, usedforsecurity=True): return hashlib.md5(data) def new_hash(hash_algorithm, *, usedforsecurity=True): |
