Skip to content
Snippets Groups Projects
Verified Commit a42c75e6 authored by Antoine R. Dumont's avatar Antoine R. Dumont
Browse files

swh.model.hashutil: Use pyblake2 dependency on python3 <= 3.4

This resolves the caveat mentioned in prior commit about not being
able to use blake2 prior to 3.5

Related T692
Closes D192
parent 24f8dd4d
No related branches found
Tags debian/1.0.1-1_swh1_bpo10+1
No related merge requests found
......@@ -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/
......
pyblake2
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment