Make generate_signature Python 3 compatible

This commit is contained in:
Karl Hobley 2014-07-16 16:19:47 +01:00
parent a7610ec7be
commit a580f7d286

View file

@ -5,6 +5,8 @@ import base64
import hmac
import hashlib
from six import b
from PIL import Image
from django.core.exceptions import ValidationError
@ -78,8 +80,8 @@ def parse_filter_spec(filter_spec):
def generate_signature(image_id, filter_spec):
# Based on libthumbor hmac generation
# https://github.com/thumbor/libthumbor/blob/b19dc58cf84787e08c8e397ab322e86268bb4345/libthumbor/crypto.py#L50
url = str(image_id) + '/' + filter_spec + '/'
return base64.urlsafe_b64encode(hmac.new(settings.SECRET_KEY, url, hashlib.sha1).digest())
url = str(image_id) + '/' + str(filter_spec) + '/'
return base64.urlsafe_b64encode(hmac.new(b(settings.SECRET_KEY), b(url), hashlib.sha1).digest())
def verify_signature(signature, image_id, filter_spec):