commit: 42fa52af521867b45b56f091c91b7b6aa78ba677 Author: Michał Górny <mgorny <AT> gentoo <DOT> org> AuthorDate: Sun Mar 12 15:33:28 2017 +0000 Commit: Michał Górny <mgorny <AT> gentoo <DOT> org> CommitDate: Mon Mar 13 21:46:29 2017 +0000 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=42fa52af
portage.checksum: Remove fallbacks for algorithms guaranteed since py2.7 The MD5, SHA1 and SHA2 algorithms are guaranteed to be available in hashlib for Python 2.7 and newer, making the fallbacks to other implementations meaningless. Remove them to simplify the code. pym/portage/checksum.py | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/pym/portage/checksum.py b/pym/portage/checksum.py index 82e8bec00..7812791ad 100644 --- a/pym/portage/checksum.py +++ b/pym/portage/checksum.py @@ -19,10 +19,10 @@ import tempfile # most preferred first. Please keep this in sync with logic below. # ================================================================ # -# MD5: hashlib, mhash -# SHA1: hashlib, mhash -# SHA256: hashlib, pycrypto, mhash -# SHA512: hashlib, mhash +# MD5: hashlib +# SHA1: hashlib +# SHA256: hashlib +# SHA512: hashlib # RMD160: hashlib, pycrypto, mhash # WHIRLPOOL: hashlib, mhash, bundled # BLAKE2B (512): hashlib (3.6+), pycrypto @@ -100,10 +100,6 @@ class _generate_hash_function(object): # WHIRLPOOL available. try: import mhash, functools - md5hash = _generate_hash_function("MD5", functools.partial(mhash.MHASH, mhash.MHASH_MD5), origin="mhash") - sha1hash = _generate_hash_function("SHA1", functools.partial(mhash.MHASH, mhash.MHASH_SHA1), origin="mhash") - sha256hash = _generate_hash_function("SHA256", functools.partial(mhash.MHASH, mhash.MHASH_SHA256), origin="mhash") - sha512hash = _generate_hash_function("SHA512", functools.partial(mhash.MHASH, mhash.MHASH_SHA512), origin="mhash") for local_name, hash_name in (("rmd160", "ripemd160"), ("whirlpool", "whirlpool")): if hasattr(mhash, 'MHASH_%s' % local_name.upper()): globals()['%shash' % local_name] = \ @@ -117,11 +113,7 @@ except ImportError: # Check for 'new' attributes, since they can be missing if the module # is broken somehow. try: - from Crypto.Hash import SHA256, RIPEMD - sha256hash_ = getattr(SHA256, 'new', None) - if sha256hash_ is not None: - sha256hash = _generate_hash_function("SHA256", - sha256hash_, origin="pycrypto") + from Crypto.Hash import RIPEMD rmd160hash_ = getattr(RIPEMD, 'new', None) if rmd160hash_ is not None: rmd160hash = _generate_hash_function("RMD160",