Refs #27795 -- Replaced force_bytes() usage in django.core.signing.

This commit is contained in:
Asif Saifuddin Auvi 2018-02-07 23:47:34 +06:00 committed by Tim Graham
parent 34b52f8572
commit b38532cd6b
1 changed files with 2 additions and 2 deletions

View File

@ -74,7 +74,7 @@ def base64_hmac(salt, value, key):
def get_cookie_signer(salt='django.core.signing.get_cookie_signer'): def get_cookie_signer(salt='django.core.signing.get_cookie_signer'):
Signer = import_string(settings.SIGNING_BACKEND) Signer = import_string(settings.SIGNING_BACKEND)
key = force_bytes(settings.SECRET_KEY) key = force_bytes(settings.SECRET_KEY) # SECRET_KEY may be str or bytes.
return Signer(b'django.http.cookies' + key, salt=salt) return Signer(b'django.http.cookies' + key, salt=salt)
@ -131,7 +131,7 @@ def loads(s, key=None, salt='django.core.signing', serializer=JSONSerializer, ma
""" """
# TimestampSigner.unsign() returns str but base64 and zlib compression # TimestampSigner.unsign() returns str but base64 and zlib compression
# operate on bytes. # operate on bytes.
base64d = force_bytes(TimestampSigner(key, salt=salt).unsign(s, max_age=max_age)) base64d = TimestampSigner(key, salt=salt).unsign(s, max_age=max_age).encode()
decompress = base64d[:1] == b'.' decompress = base64d[:1] == b'.'
if decompress: if decompress:
# It's compressed; uncompress it first # It's compressed; uncompress it first