Permalink
Browse files

Simplify wrapper, as digest_size is known in advance each time.

  • Loading branch information...
1 parent 9620229 commit dd3f0007c546ff3f9258719226cb065a30155b2c Legrandin committed Feb 7, 2011
Showing with 9 additions and 7 deletions.
  1. +3 −3 lib/Crypto/Hash/MD5.py
  2. +3 −3 lib/Crypto/Hash/SHA.py
  3. +3 −1 lib/Crypto/Util/wrapper.py
View
6 lib/Crypto/Hash/MD5.py
@@ -38,17 +38,17 @@ def new(data=""):
obj = Wrapper(hashFactory, data)
obj.oid = oid
obj.new = globals()['new']
+ if not hasattr(obj, 'digest_size'):
+ obj.digest_size = digest_size
return obj
try:
# The md5 module is deprecated in Python 2.6, so use hashlib when possible.
import hashlib
hashFactory = hashlib.md5
- digest_size = new().digest_size
except ImportError:
import md5
hashFactory = md5
- if hasattr(md5, 'digestsize'):
- digest_size = md5.digestsize
+digest_size = 16
View
6 lib/Crypto/Hash/SHA.py
@@ -38,17 +38,17 @@ def new(data=""):
obj = Wrapper(hashFactory, data)
obj.oid = oid
obj.new = globals()['new']
+ if not hasattr(obj, 'digest_size'):
+ obj.digest_size = digest_size
return obj
try:
# The sha module is deprecated in Python 2.6, so use hashlib when possible.
import hashlib
hashFactory = hashlib.sha1
- digest_size = new().digest_size
except ImportError:
import sha
hashFactory = sha
- if hasattr(sha, 'digestsize'):
- digest_size = sha.digestsize
+digest_size = 20
View
4 lib/Crypto/Util/wrapper.py
@@ -40,5 +40,7 @@ def __getattr__(self, name):
try:
return getattr(getattr(self,'_wrapped'),name)
except AttributeError:
- return getattr(self,name)
+ if hasattr(self, name):
+ return getattr(self,name)
+ raise

0 comments on commit dd3f000

Please sign in to comment.