Fix handling of byte strings and large ints
This commit is contained in:
parent
02bafb1613
commit
a7b6cb5c23
1 changed files with 11 additions and 6 deletions
|
@ -148,19 +148,24 @@ class UserAuthentication(object):
|
||||||
""" Returns the secret key to use for encrypting and decrypting. """
|
""" Returns the secret key to use for encrypting and decrypting. """
|
||||||
from app import app
|
from app import app
|
||||||
app_secret_key = app.config['SECRET_KEY']
|
app_secret_key = app.config['SECRET_KEY']
|
||||||
|
secret_key = None
|
||||||
|
|
||||||
# First try parsing the key as an int.
|
# First try parsing the key as an int.
|
||||||
try:
|
try:
|
||||||
big_int = int(app_secret_key)
|
big_int = int(app_secret_key)
|
||||||
secret_key = bytearray.fromhex('{:02x}'.format(big_int))
|
secret_key = str(bytearray.fromhex('{:02x}'.format(big_int)))
|
||||||
except ValueError:
|
except ValueError:
|
||||||
secret_key = app_secret_key
|
pass
|
||||||
|
|
||||||
# Next try parsing it as an UUID.
|
# Next try parsing it as an UUID.
|
||||||
|
if secret_key is None:
|
||||||
try:
|
try:
|
||||||
secret_key = uuid.UUID(app_secret_key).bytes
|
secret_key = uuid.UUID(app_secret_key).bytes
|
||||||
except ValueError:
|
except ValueError:
|
||||||
secret_key = app_secret_key
|
pass
|
||||||
|
|
||||||
|
if secret_key is None:
|
||||||
|
secret_key = str(bytearray(map(ord, app_secret_key)))
|
||||||
|
|
||||||
# Otherwise, use the bytes directly.
|
# Otherwise, use the bytes directly.
|
||||||
return ''.join(itertools.islice(itertools.cycle(secret_key), 32))
|
return ''.join(itertools.islice(itertools.cycle(secret_key), 32))
|
||||||
|
|
Reference in a new issue