commit:     3140392cd396a8e76525d95758ec71c8b3871a06
Author:     Michał Górny <mgorny <AT> gentoo <DOT> org>
AuthorDate: Fri Oct 20 18:58:56 2017 +0000
Commit:     Michał Górny <mgorny <AT> gentoo <DOT> org>
CommitDate: Fri Oct 20 21:51:37 2017 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=3140392c

portage.checksum: Support pyblake2 fallback for BLAKE2 hashes

Approved-by: Zac Medico <zmedico <AT> gentoo.org>
Closes: https://github.com/gentoo/portage/pull/222

 .travis.yml             |  2 ++
 pym/portage/checksum.py | 15 +++++++++++++--
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 20078530e..ebcfbeab9 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -12,6 +12,8 @@ install:
     # python3.6+ has sha3 built-in, for older versions install pysha3
     # (except for pypy where pysha3 is broken)
     - "[[ ${TRAVIS_PYTHON_VERSION} == 3.[6789] || ${TRAVIS_PYTHON_VERSION} == 
pypy ]] || pip install pysha3"
+    # python3.6+ has blake2 built-in, for older versions install pyblake2
+    - "[[ ${TRAVIS_PYTHON_VERSION} == 3.[6789] ]] || pip install pyblake2"
     # always install pygost for Streebog
     - pip install pygost
 

diff --git a/pym/portage/checksum.py b/pym/portage/checksum.py
index ff132751b..ad090ddb3 100644
--- a/pym/portage/checksum.py
+++ b/pym/portage/checksum.py
@@ -27,8 +27,8 @@ import tempfile
 # SHA512: hashlib
 # RMD160: hashlib, pycrypto, mhash
 # WHIRLPOOL: hashlib, mhash, bundled
-# BLAKE2B (512): hashlib (3.6+), pycrypto
-# BLAKE2S (512): hashlib (3.6+), pycrypto
+# BLAKE2B (512): hashlib (3.6+), pyblake2, pycrypto
+# BLAKE2S (512): hashlib (3.6+), pyblake2, pycrypto
 # SHA3_256: hashlib (3.6+), pysha3, pycrypto
 # SHA3_512: hashlib (3.6+), pysha3, pycrypto
 
@@ -124,6 +124,17 @@ for local_name, hash_name in (
                        origin='hashlib')
 
 
+# Support using pyblake2 as fallback for python<3.6
+if "BLAKE2B" not in hashfunc_map or "BLAKE2S" not in hashfunc_map:
+       try:
+               import pyblake2
+
+               _generate_hash_function("BLAKE2B", pyblake2.blake2b, 
origin="pyblake2")
+               _generate_hash_function("BLAKE2S", pyblake2.blake2s, 
origin="pyblake2")
+       except ImportError:
+               pass
+
+
 # Support using pysha3 as fallback for python<3.6
 if "SHA3_256" not in hashfunc_map or "SHA3_512" not in hashfunc_map:
        try:

Reply via email to