~ubuntu-branches/ubuntu/saucy/beaker/saucy

« back to all changes in this revision

Viewing changes to beaker/crypto/util.py

  • Committer: Bazaar Package Importer
  • Author(s): Piotr Ożarowski
  • Date: 2010-03-03 00:37:43 UTC
  • mfrom: (1.1.16 upstream) (2.1.18 sid)
  • Revision ID: james.westby@ubuntu.com-20100303003743-ydl9a2st185leauo
Tags: 1.5.3-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from warnings import warn
 
2
from beaker import util
 
3
 
 
4
 
 
5
try:
 
6
    # Use PyCrypto (if available)
 
7
    from Crypto.Hash import HMAC as hmac, SHA as hmac_sha1
 
8
    sha1 = hmac_sha1.new
 
9
    
 
10
except ImportError:
 
11
    
 
12
    # PyCrypto not available.  Use the Python standard library.
 
13
    import hmac
 
14
 
 
15
    # When using the stdlib, we have to make sure the hmac version and sha
 
16
    # version are compatible
 
17
    if util.py24:
 
18
        from sha import sha as sha1
 
19
        import sha as hmac_sha1
 
20
    else:
 
21
        # NOTE: We have to use the callable with hashlib (hashlib.sha1),
 
22
        # otherwise hmac only accepts the sha module object itself
 
23
        from hashlib import sha1
 
24
        hmac_sha1 = sha1
 
25
 
 
26
 
 
27
if util.py24:
 
28
    from md5 import md5
 
29
else:
 
30
    from hashlib import md5