summaryrefslogtreecommitdiff
blob: 9ee7e17eb0f651ea190072a8da279a814219d573 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#From: Dwayne C. Litzenberger <dlitz@dlitz.net>
#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: pycrypto-2.0.1-2.6_hashlib.patch,v 1.1 2009/03/01 08:24:02 neurogeek Exp $"
 
-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: pycrypto-2.0.1-2.6_hashlib.patch,v 1.1 2009/03/01 08:24:02 neurogeek Exp $"
 
-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 <dlitz@dlitz.net>
#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()