python3: use smart bytes for signatures

This commit is contained in:
Frédéric Péters 2018-03-25 16:19:56 +02:00
parent b26cc32c59
commit ae15cab91e
1 changed files with 2 additions and 1 deletions

View File

@ -21,6 +21,7 @@ import hashlib
import random
from django.conf import settings
from django.utils.encoding import smart_bytes
from django.utils.http import quote, urlencode
from django.utils.six.moves.urllib.parse import urlparse, urlunparse, parse_qs
@ -51,7 +52,7 @@ def sign_query(query, key, algo='sha256', timestamp=None, nonce=None):
def sign_string(s, key, algo='sha256', timedelta=30):
digestmod = getattr(hashlib, algo)
hash = hmac.HMAC(str(key), digestmod=digestmod, msg=s)
hash = hmac.HMAC(smart_bytes(key), digestmod=digestmod, msg=smart_bytes(s))
return hash.digest()
def check_request_signature(django_request, keys=[]):