diff --git a/debian/control b/debian/control index c20e5f56ce0064a90fd9c8eec7071eca19e028c0..3e7fc44efb63e204152845e0ff6f697268c39e0c 100644 --- a/debian/control +++ b/debian/control @@ -7,6 +7,7 @@ Build-Depends: debhelper (>= 9), python3-all, python3-nose, python3-setuptools, + python3-pyblake2, python3-vcversioner Standards-Version: 3.9.6 Homepage: https://forge.softwareheritage.org/diffusion/DMOD/ diff --git a/requirements-swh.txt b/requirements-swh.txt index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..fbe63bd90787cff4ad7e1a774a2cbffa4a20b17f 100644 --- a/requirements-swh.txt +++ b/requirements-swh.txt @@ -0,0 +1 @@ +pyblake2 diff --git a/swh/model/hashutil.py b/swh/model/hashutil.py index aa0478693152e487c21b98b83c1e7a1816641be1..20bde9795e370160e3e4d97253d868087c59586c 100644 --- a/swh/model/hashutil.py +++ b/swh/model/hashutil.py @@ -28,6 +28,7 @@ import binascii import functools import hashlib import os +import sys from io import BytesIO @@ -41,6 +42,15 @@ DEFAULT_ALGORITHMS = set(['sha1', 'sha256', 'sha1_git']) # FWIW coreutils' sha1sum uses 32768 HASH_BLOCK_SIZE = 32768 +# Prior to python3.4, only blake2 is available through pyblake2 module +# From 3.5 onwards, it's been integrated in python +if sys.version_info.major == 3 and sys.version_info.minor <= 4: + import pyblake2 + # register those hash algorithms in hashlib + __cache = hashlib.__builtin_constructor_cache + __cache['blake2s256'] = pyblake2.blake2s + __cache['blake2b512'] = pyblake2.blake2b + def _new_git_hash(base_algo, git_type, length): """Initialize a digest object (as returned by python's hashlib) for the