diff --git a/django/core/signing.py b/django/core/signing.py
index 6fc76bc..d99dd5a 100644
a
|
b
|
from django.conf import settings
|
43 | 43 | from django.core.exceptions import ImproperlyConfigured |
44 | 44 | from django.utils import baseconv |
45 | 45 | from django.utils.crypto import constant_time_compare, salted_hmac |
46 | | from django.utils.encoding import smart_bytes |
| 46 | from django.utils.encoding import force_bytes, force_str, force_text |
47 | 47 | from django.utils.importlib import import_module |
48 | 48 | |
49 | 49 | |
… |
… |
class SignatureExpired(BadSignature):
|
62 | 62 | |
63 | 63 | |
64 | 64 | def b64_encode(s): |
65 | | return base64.urlsafe_b64encode(smart_bytes(s)).decode('ascii').strip('=') |
| 65 | return base64.urlsafe_b64encode(force_bytes(s)).decode('ascii').strip('=') |
66 | 66 | |
67 | 67 | |
68 | 68 | def b64_decode(s): |
69 | 69 | pad = '=' * (-len(s) % 4) |
70 | | return base64.urlsafe_b64decode(smart_bytes(s + pad)).decode('ascii') |
| 70 | return base64.urlsafe_b64decode(force_bytes(s + pad)).decode('ascii') |
71 | 71 | |
72 | 72 | |
73 | 73 | def base64_hmac(salt, value, key): |
… |
… |
def dumps(obj, key=None, salt='django.core.signing', serializer=JSONSerializer,
|
123 | 123 | |
124 | 124 | if compress: |
125 | 125 | # Avoid zlib dependency unless compress is being used |
126 | | compressed = zlib.compress(smart_bytes(data)) |
| 126 | compressed = zlib.compress(force_bytes(data)) |
127 | 127 | if len(compressed) < (len(data) - 1): |
128 | 128 | data = compressed |
129 | 129 | is_compressed = True |
… |
… |
class Signer(object):
|
160 | 160 | return base64_hmac(self.salt + 'signer', value, self.key) |
161 | 161 | |
162 | 162 | def sign(self, value): |
163 | | return '%s%s%s' % (value, self.sep, self.signature(value)) |
| 163 | return force_str('%s%s%s' % (value, self.sep, self.signature(value))) |
164 | 164 | |
165 | 165 | def unsign(self, signed_value): |
| 166 | signed_value = force_text(signed_value) |
166 | 167 | if not self.sep in signed_value: |
167 | 168 | raise BadSignature('No "%s" found in value' % self.sep) |
168 | 169 | value, sig = signed_value.rsplit(self.sep, 1) |