Cast value to bytes before doing hash.

Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
Roberto Rosario
2018-09-06 03:35:50 -04:00
parent 44ac0932b3
commit 9eb3d39558
2 changed files with 7 additions and 7 deletions

View File

@@ -6,7 +6,7 @@ import logging
from PIL import Image, ImageColor, ImageFilter
from django.utils.translation import string_concat, ugettext_lazy as _
from django.utils.encoding import force_text
from django.utils.encoding import force_bytes, force_text
logger = logging.getLogger(__name__)
@@ -62,14 +62,14 @@ class BaseTransformation(object):
self.kwargs[argument_name] = kwargs.get(argument_name)
def cache_hash(self):
result = hashlib.sha256(self.name)
result = hashlib.sha256(force_bytes(self.name))
# Sort arguments for guaranteed repeatability
for key, value in sorted(self.kwargs.items()):
result.update(force_text(key))
result.update(force_text(value))
result.update(force_bytes(key))
result.update(force_bytes(value))
return result.hexdigest()
return force_bytes(result.hexdigest())
def execute_on(self, image):
self.image = image

View File

@@ -10,7 +10,7 @@ import uuid
from django.conf import settings
from django.core.files import locks
from django.utils.encoding import force_text
from django.utils.encoding import force_bytes, force_text
from common.settings import setting_temporary_directory
@@ -23,7 +23,7 @@ lock = threading.Lock()
logger = logging.getLogger(__name__)
lock_file = os.path.join(
setting_temporary_directory.value, hashlib.sha256(settings.SECRET_KEY).hexdigest()
setting_temporary_directory.value, hashlib.sha256(force_bytes(settings.SECRET_KEY)).hexdigest()
)
open(lock_file, 'a').close()
logger.debug('lock_file: %s', lock_file)