Commits

Andriy Kornatskyy committed c6d93e1

Added import from hashlib for hash algorithms as well as openssl digests: ripemd160 and whirlpool.

Comments (0)

Files changed (2)

src/wheezy/security/crypto/comp.py

 # Hash functions
 try:  # pragma: nocover
     # Python 2.5+
-    from hashlib import md5
-    from hashlib import sha1
+    from hashlib import md5, sha1, sha224, sha256, sha384, sha512
     digest_size = lambda d: d().digest_size
+
+    try:
+        from hashlib import new as openssl_hash
+        ripemd160 = lambda: openssl_hash('ripemd160')
+        whirlpool = lambda: openssl_hash('whirlpool')
+    except ValueError:
+        ripemd160 = None
+        whirlpool = None
 except ImportError:  # pragma: nocover
     import md5
     import sha as sha1
+    sha224 = ssa256 = ssh384 = ssh512 = ripemd160 = whirlpool = None
     digest_size = lambda d: d.digest_size
 
-
 # Encryption interface
 block_size = None
 encrypt = None

src/wheezy/security/crypto/ticket.py

         cypher.
 
         >>> from wheezy.security.crypto.comp import n
-        >>> t = Ticket()
+        >>> t = Ticket(digestmod=sha1)
         >>> len(t.encode(''))
         72
         >>> x = t.encode('hello')
     def __init__(self, max_age=900, salt='', digestmod=None,
             cypher=aes128, options=None):
         self.max_age = max_age
-        digestmod = digestmod or sha1
+        if not digestmod:
+            warn('Ticket: digestmod is not specified, fallback to sha1',
+                    stacklevel=2)
+            digestmod = sha1
         options = options or {}
         key = b(salt + options.get('CRYPTO_VALIDATION_KEY', ''))
         key = ensure_strong_key(key)