mirror of
https://github.com/Legrandin/pycryptodome.git
synced 2025-11-11 19:12:15 +00:00
Simplify wrapper, as digest_size is known in advance each time.
This commit is contained in:
parent
9620229917
commit
dd3f0007c5
3 changed files with 9 additions and 7 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -40,5 +40,7 @@ class Wrapper:
|
|||
try:
|
||||
return getattr(getattr(self,'_wrapped'),name)
|
||||
except AttributeError:
|
||||
if hasattr(self, name):
|
||||
return getattr(self,name)
|
||||
raise
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue