fallback to old modules for centos5 (python 2.4)
[plcapi.git] / PLC / Auth.py
index 945c8ce..08c9d2c 100644 (file)
@@ -9,7 +9,10 @@
 #
 
 import crypt
-import hashlib
+try:
+    from hashlib import sha1 as sha
+except ImportError:
+    import sha
 import hmac
 import time
 
@@ -257,7 +260,7 @@ class BootAuth(Auth):
             # We encode in UTF-8 before calculating the HMAC, which is
             # an 8-bit algorithm.
             # python 2.6 insists on receiving a 'str' as opposed to a 'unicode'
-            digest = hmac.new(str(key), msg.encode('utf-8'), hashlib.sha1).hexdigest()
+            digest = hmac.new(str(key), msg.encode('utf-8'), sha).hexdigest()
 
             if digest != auth['value']:
                 raise PLCAuthenticationFailure, "Call could not be authenticated"