Commits

Ben Bangert committed fe9c7bc Merge

Merge

Comments (0)

Files changed (4)

beaker/crypto/pbkdf2.py

 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 = macmodule.new
+        if not callable(digestmodule):
+            digestmodule = digestmodule.new
         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 self.__macmodule.new(key=key, msg=msg,
+        return self.__macmodule(key=key, msg=msg,
             digestmod=self.__digestmodule).digest()
     
     def read(self, bytes):

beaker/session.py

 import cPickle
 import Cookie
 import hmac
-import md5
 import os
 import random
-import sha
 import time
 from datetime import datetime, timedelta
+try:
+    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
 try:
     
     def value_decode(self, val):
         val = val.strip('"')
-        sig = hmac.new(self.secret, val[40:], sha).hexdigest()
+        sig = hmac.new(self.secret, val[40:], sha1).hexdigest()
         if sig != val[:40]:
             return None, val
         else:
             return val[40:], val
     
     def value_encode(self, val):
-        sig = hmac.new(self.secret, val, sha).hexdigest()
+        sig = hmac.new(self.secret, val, sha1).hexdigest()
         return str(val), ("%s%s" % (sig, val))
 
 
                     raise
         
     def _create_id(self):
-        self.id = md5.new(
-            md5.new("%f%s%f%s" % (time.time(), id({}), random.random(), os.getpid()) ).hexdigest(), 
+        self.id = md5(
+            md5("%f%s%f%s" % (time.time(), id({}), random.random(), os.getpid()) ).hexdigest(), 
         ).hexdigest()
         self.is_new = True
         if self.use_cookies:
             return cPickle.loads(data)
     
     def _make_id(self):
-        return md5.new(md5.new(
+        return md5(md5(
             "%f%s%f%d" % (time.time(), id({}), random.random(), os.getpid())
             ).hexdigest()
         ).hexdigest()
 
 from datetime import datetime, timedelta
 import os
-import sha
 import string
 import types
 import weakref
     Set = set
 except NameError:
     from sets import Set
+try:
+    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 = sha.new(ident).hexdigest()
+        ident = sha1(ident).hexdigest()
     
     ident = os.path.basename(ident)
 
 from setuptools import setup, find_packages
 
-version = '1.0.1'
+version = '1.0.2'
 
 setup(name='Beaker',
       version=version,
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.