1 |
The MD5, SHA1 and SHA2 algorithms are guaranteed to be available in |
2 |
hashlib for Python 2.7 and newer, making the fallbacks to other |
3 |
implementations meaningless. Remove them to simplify the code. |
4 |
--- |
5 |
pym/portage/checksum.py | 18 +++++------------- |
6 |
1 file changed, 5 insertions(+), 13 deletions(-) |
7 |
|
8 |
diff --git a/pym/portage/checksum.py b/pym/portage/checksum.py |
9 |
index 82e8bec00..7812791ad 100644 |
10 |
--- a/pym/portage/checksum.py |
11 |
+++ b/pym/portage/checksum.py |
12 |
@@ -19,10 +19,10 @@ import tempfile |
13 |
# most preferred first. Please keep this in sync with logic below. |
14 |
# ================================================================ |
15 |
# |
16 |
-# MD5: hashlib, mhash |
17 |
-# SHA1: hashlib, mhash |
18 |
-# SHA256: hashlib, pycrypto, mhash |
19 |
-# SHA512: hashlib, mhash |
20 |
+# MD5: hashlib |
21 |
+# SHA1: hashlib |
22 |
+# SHA256: hashlib |
23 |
+# SHA512: hashlib |
24 |
# RMD160: hashlib, pycrypto, mhash |
25 |
# WHIRLPOOL: hashlib, mhash, bundled |
26 |
# BLAKE2B (512): hashlib (3.6+), pycrypto |
27 |
@@ -100,10 +100,6 @@ class _generate_hash_function(object): |
28 |
# WHIRLPOOL available. |
29 |
try: |
30 |
import mhash, functools |
31 |
- md5hash = _generate_hash_function("MD5", functools.partial(mhash.MHASH, mhash.MHASH_MD5), origin="mhash") |
32 |
- sha1hash = _generate_hash_function("SHA1", functools.partial(mhash.MHASH, mhash.MHASH_SHA1), origin="mhash") |
33 |
- sha256hash = _generate_hash_function("SHA256", functools.partial(mhash.MHASH, mhash.MHASH_SHA256), origin="mhash") |
34 |
- sha512hash = _generate_hash_function("SHA512", functools.partial(mhash.MHASH, mhash.MHASH_SHA512), origin="mhash") |
35 |
for local_name, hash_name in (("rmd160", "ripemd160"), ("whirlpool", "whirlpool")): |
36 |
if hasattr(mhash, 'MHASH_%s' % local_name.upper()): |
37 |
globals()['%shash' % local_name] = \ |
38 |
@@ -117,11 +113,7 @@ except ImportError: |
39 |
# Check for 'new' attributes, since they can be missing if the module |
40 |
# is broken somehow. |
41 |
try: |
42 |
- from Crypto.Hash import SHA256, RIPEMD |
43 |
- sha256hash_ = getattr(SHA256, 'new', None) |
44 |
- if sha256hash_ is not None: |
45 |
- sha256hash = _generate_hash_function("SHA256", |
46 |
- sha256hash_, origin="pycrypto") |
47 |
+ from Crypto.Hash import RIPEMD |
48 |
rmd160hash_ = getattr(RIPEMD, 'new', None) |
49 |
if rmd160hash_ is not None: |
50 |
rmd160hash = _generate_hash_function("RMD160", |
51 |
-- |
52 |
2.12.0 |