Mercurial > hgrepos > Python > apps > py-cutils
changeset 88:f69353f26937
Support for using the pyblake2 package if native support for BLAKE2 is not available in hashlib.
This is to support BLAKE2 on Python2 and pre-Python 3.6.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Thu, 21 Apr 2022 00:24:49 +0200 |
| parents | b46673c42894 |
| children | 72684020f2f3 |
| files | cutils/shasum.py |
| diffstat | 1 files changed, 22 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/cutils/shasum.py Thu Apr 21 00:09:17 2022 +0200 +++ b/cutils/shasum.py Thu Apr 21 00:24:49 2022 +0200 @@ -382,19 +382,37 @@ def get_blake2b(): """Get the factory for blake2b""" - return hashlib.blake2b + try: + return hashlib.blake2b + except AttributeError: + import pyblake2 + return pyblake2.blake2b def get_blake2s(): """Get the factory for blake2s""" - return hashlib.blake2s + try: + return hashlib.blake2s + except AttributeError: + import pyblake2 + return pyblake2.blake2s def get_blake2_256(): """Get the factory for blake2-256""" - def _get_blake(): - return hashlib.blake2b(digest_size=32) + try: + hashlib.blake2b + except AttributeError: + import pyblake2 + + def _get_blake(): + return pyblake2.blake2b(digest_size=32) + + else: + + def _get_blake(): + return hashlib.blake2b(digest_size=32) return _get_blake
