Ben Bangert  committed fe9c7bc Merge


  • Participants
  • Parent commits 0585ac4, 985931b

Comments (0)

Files changed (4)

File beaker/crypto/

 except ImportError:
     # PyCrypto not available.  Use the Python standard library.
     import hmac as HMAC
-    import sha as SHA1
+    try:
+        from hashlib import sha1 as SHA1
+    except ImportError:
+        # NOTE: We have to use the callable with hashlib (hashlib.sha1),
+        # otherwise hmac only accepts the sha module object itself
+        import sha as SHA1
 def strxor(a, b):
     return "".join([chr(ord(x) ^ ord(y)) for (x, y) in zip(a, b)])
     def __init__(self, passphrase, salt, iterations=1000,
                  digestmodule=SHA1, macmodule=HMAC):
+        # Support both sha/md5 style modules and hashlib functions
+        if not callable(macmodule):
+            macmodule =
+        if not callable(digestmodule):
+            digestmodule =
         self.__macmodule = macmodule
         self.__digestmodule = digestmodule
         self._setup(passphrase, salt, iterations, self._pseudorandom)
     def _pseudorandom(self, key, msg):
         """Pseudorandom function.  e.g. HMAC-SHA1"""
-        return, msg=msg,
+        return self.__macmodule(key=key, msg=msg,
     def read(self, bytes):

File beaker/

 import cPickle
 import Cookie
 import hmac
-import md5
 import os
 import random
-import sha
 import time
 from datetime import datetime, timedelta
+    from hashlib import md5, sha1
+except ImportError:
+    from md5 import md5
+    # NOTE: We have to use the callable with hashlib (hashlib.sha1),
+    # otherwise hmac only accepts the sha module object itself
+    import sha as sha1
 # Check for pycryptopp encryption for AES
     def value_decode(self, val):
         val = val.strip('"')
-        sig =, val[40:], sha).hexdigest()
+        sig =, val[40:], sha1).hexdigest()
         if sig != val[:40]:
             return None, val
             return val[40:], val
     def value_encode(self, val):
-        sig =, val, sha).hexdigest()
+        sig =, val, sha1).hexdigest()
         return str(val), ("%s%s" % (sig, val))
     def _create_id(self):
- =
-  "%f%s%f%s" % (time.time(), id({}), random.random(), os.getpid()) ).hexdigest(), 
+ = md5(
+            md5("%f%s%f%s" % (time.time(), id({}), random.random(), os.getpid()) ).hexdigest(), 
         self.is_new = True
         if self.use_cookies:
             return cPickle.loads(data)
     def _make_id(self):
-        return
+        return md5(md5(
             "%f%s%f%d" % (time.time(), id({}), random.random(), os.getpid())

File beaker/

 from datetime import datetime, timedelta
 import os
-import sha
 import string
 import types
 import weakref
     Set = set
 except NameError:
     from sets import Set
+    from hashlib import sha1
+except ImportError:
+    from sha import sha as sha1
 from beaker.converters import asbool
     ident = string.join(identifiers, "_")
     if digest_filenames:
-        ident =
+        ident = sha1(ident).hexdigest()
     ident = os.path.basename(ident)
 from setuptools import setup, find_packages
-version = '1.0.1'
+version = '1.0.2'