From: Dwayne C. Litzenberger Date: Sun, 14 Sep 2008 19:30:59 +0000 (-0400) Subject: Python 2.6 compatibility: When possible, use hashlib instead of the deprecated 'md5... X-Git-Url: http://gitweb.pycrypto.org/?p=crypto%2Fpycrypto-2.x.git;a=commitdiff_plain;h=d2311689910240e425741a546576129f4c9735e2 Python 2.6 compatibility: When possible, use hashlib instead of the deprecated 'md5' and 'sha' modules --- diff --git a/Hash/MD5.py b/Hash/MD5.py index bdbc62a..e79a85f 100644 --- a/Hash/MD5.py +++ b/Hash/MD5.py @@ -3,11 +3,21 @@ __revision__ = "$Id$" -from md5 import * +__all__ = ['new', 'digest_size'] -import md5 -if hasattr(md5, 'digestsize'): - digest_size = digestsize - del digestsize -del md5 +try: + # The md5 module is deprecated in Python 2.6, so use hashlib when possible. + import hashlib + def new(data=""): + return hashlib.md5(data) + digest_size = new().digest_size + +except ImportError: + from md5 import * + + import md5 + if hasattr(md5, 'digestsize'): + digest_size = digestsize + del digestsize + del md5 diff --git a/Hash/SHA.py b/Hash/SHA.py index dc05502..f4128ec 100644 --- a/Hash/SHA.py +++ b/Hash/SHA.py @@ -3,9 +3,19 @@ __revision__ = "$Id$" -from sha import * -import sha -if hasattr(sha, 'digestsize'): - digest_size = digestsize - del digestsize -del sha +__all__ = ['new', 'digest_size'] + +try: + # The md5 module is deprecated in Python 2.6, so use hashlib when possible. + import hashlib + def new(data=""): + return hashlib.sha1(data) + digest_size = new().digest_size + +except ImportError: + from sha import * + import sha + if hasattr(sha, 'digestsize'): + digest_size = digestsize + del digestsize + del sha From: Dwayne C. Litzenberger Date: Sun, 14 Sep 2008 21:38:52 +0000 (-0400) Subject: Python 2.6 compatibility: Use Hash.MD5 instead of Python "md5" module in the HMAC... X-Git-Url: http://gitweb.pycrypto.org/?p=crypto%2Fpycrypto-2.0.x.git;a=commitdiff_plain;h=84b793416b52311643bfd456a4544444afbfb5da Python 2.6 compatibility: Use Hash.MD5 instead of Python "md5" module in the HMAC module. --- diff --git a/Hash/HMAC.py b/Hash/HMAC.py index b8a9229..6ed9556 100644 --- a/Hash/HMAC.py +++ b/Hash/HMAC.py @@ -33,8 +33,8 @@ class HMAC: digestmod: A module supporting PEP 247. Defaults to the md5 module. """ if digestmod == None: - import md5 - digestmod = md5 + import MD5 + digestmod = MD5 self.digestmod = digestmod self.outer = digestmod.new()