Mercurial > hgrepos > Python > apps > py-cutils
comparison cutils/shasum.py @ 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 |
comparison
equal
deleted
inserted
replaced
| 87:b46673c42894 | 88:f69353f26937 |
|---|---|
| 380 return None | 380 return None |
| 381 | 381 |
| 382 | 382 |
| 383 def get_blake2b(): | 383 def get_blake2b(): |
| 384 """Get the factory for blake2b""" | 384 """Get the factory for blake2b""" |
| 385 return hashlib.blake2b | 385 try: |
| 386 return hashlib.blake2b | |
| 387 except AttributeError: | |
| 388 import pyblake2 | |
| 389 return pyblake2.blake2b | |
| 386 | 390 |
| 387 | 391 |
| 388 def get_blake2s(): | 392 def get_blake2s(): |
| 389 """Get the factory for blake2s""" | 393 """Get the factory for blake2s""" |
| 390 return hashlib.blake2s | 394 try: |
| 395 return hashlib.blake2s | |
| 396 except AttributeError: | |
| 397 import pyblake2 | |
| 398 return pyblake2.blake2s | |
| 391 | 399 |
| 392 | 400 |
| 393 def get_blake2_256(): | 401 def get_blake2_256(): |
| 394 """Get the factory for blake2-256""" | 402 """Get the factory for blake2-256""" |
| 395 | 403 |
| 396 def _get_blake(): | 404 try: |
| 397 return hashlib.blake2b(digest_size=32) | 405 hashlib.blake2b |
| 406 except AttributeError: | |
| 407 import pyblake2 | |
| 408 | |
| 409 def _get_blake(): | |
| 410 return pyblake2.blake2b(digest_size=32) | |
| 411 | |
| 412 else: | |
| 413 | |
| 414 def _get_blake(): | |
| 415 return hashlib.blake2b(digest_size=32) | |
| 398 | 416 |
| 399 return _get_blake | 417 return _get_blake |
| 400 | 418 |
| 401 | 419 |
| 402 def argv2algo(s): | 420 def argv2algo(s): |
