Commits

Anonymous committed 4e9d8ec

sha haslib warnings with later versions of Python 2.x

  • Participants
  • Parent commits 5972466

Comments (0)

Files changed (2)

File tlslite/utils/RSAKey.py

         """
         if not isinstance(bytes, type("")):
             bytes = bytesToString(bytes)
-        hashBytes = stringToBytes(sha.sha(bytes).digest())
+        m = shachecksum()
+        m.update(bytes)
+        hashBytes = stringToBytes(m.digest())
         prefixedHashBytes = self._addPKCS1SHA1Prefix(hashBytes)
         sigBytes = self.sign(prefixedHashBytes)
         return sigBytes
         """
         if not isinstance(bytes, type("")):
             bytes = bytesToString(bytes)
-        hashBytes = stringToBytes(sha.sha(bytes).digest())
+        m = shachecksum()
+        m.update(bytes)
+        hashBytes = stringToBytes(m.digest())
         prefixedHashBytes = self._addPKCS1SHA1Prefix(hashBytes)
         return self.verify(sigBytes, prefixedHashBytes)
 

File tlslite/utils/cryptomath.py

 import math
 import base64
 import binascii
-import sha
+try:
+    import hashlib
+    shachecksum = hashlib.sha1
+except ImportError:
+    # pre 2.6/2.5
+    import sha
+    shachecksum = sha.new
+
 
 from compat import *
 
     return int(math.ceil(bits / 8.0))
 
 def hashAndBase64(s):
-    return stringToBase64(sha.sha(s).digest())
+    m = shachecksum()
+    m.update(s)
+    return stringToBase64(m.digest())
 
 def getBase64Nonce(numChars=22): #defaults to an 132 bit nonce
     bytes = getRandomBytes(numChars)