Ticket #12362: messages-hmac-py2.4.diff

File messages-hmac-py2.4.diff, 1.7 KB (added by Jeremy Dunck, 14 years ago)

Existing python 2.4 tests cover this, so no new tests are needed.

  • django/contrib/messages/storage/cookie.py

    diff --git a/django/contrib/messages/storage/cookie.py b/django/contrib/messages/storage/cookie.py
    index 248791d..1ac1afe 100644
    a b  
    11import hmac
    22
    33from django.conf import settings
    4 from django.utils.hashcompat import sha_constructor
     4from django.utils.hashcompat import sha_hmac
    55from django.contrib.messages import constants
    66from django.contrib.messages.storage.base import BaseStorage, Message
    77from django.utils import simplejson as json
    class MessageDecoder(json.JSONDecoder):  
    4141        decoded = super(MessageDecoder, self).decode(s, **kwargs)
    4242        return self.process_messages(decoded)
    4343
    44 
    4544class CookieStorage(BaseStorage):
    4645    """
    4746    Stores messages in a cookie.
    class CookieStorage(BaseStorage):  
    103102        SECRET_KEY, modified to make it unique for the present purpose.
    104103        """
    105104        key = 'django.contrib.messages' + settings.SECRET_KEY
    106         return hmac.new(key, value, sha_constructor).hexdigest()
     105        return hmac.new(key, value, sha_hmac).hexdigest()
    107106
    108107    def _encode(self, messages, encode_empty=False):
    109108        """
  • django/utils/hashcompat.py

    diff --git a/django/utils/hashcompat.py b/django/utils/hashcompat.py
    index 8880d92..b1e6021 100644
    a b available.  
    88try:
    99    import hashlib
    1010    md5_constructor = hashlib.md5
     11    md5_hmac = md5_constructor
    1112    sha_constructor = hashlib.sha1
     13    sha_hmac = sha_constructor
    1214except ImportError:
    1315    import md5
    1416    md5_constructor = md5.new
     17    md5_hmac = md5
    1518    import sha
    1619    sha_constructor = sha.new
     20    sha_hmac = sha
Back to Top