comparison cutils/util/__init__.py @ 365:d5c920ace3cb

treesum: FIX: Python<2.7.9 has no hashlib.algorithms_available: fall back to hashlib.algorithms in this case
author Franz Glasner <fzglas.hg@dom66.de>
date Wed, 09 Apr 2025 22:14:49 +0200
parents 48430941c18c
children bfe1160fbfd3
comparison
equal deleted inserted replaced
364:bbfcdbd75bfe 365:d5c920ace3cb
81 Prefer BLAKE2b-256, SHA256 or SHA1 -- in this order. 81 Prefer BLAKE2b-256, SHA256 or SHA1 -- in this order.
82 82
83 Does not consider :mod:`pyblake2` if it is available eventually. 83 Does not consider :mod:`pyblake2` if it is available eventually.
84 84
85 """ 85 """
86 if "blake2b" in hashlib.algorithms_available: 86 # Python <2.7.9 has no algorithms_available: fall back to algorithms
87 try:
88 algos = hashlib.algorithms_available
89 except AttributeError:
90 try:
91 algos = hashlib.algorithms
92 except AttributeError:
93 algos = []
94 if "blake2b" in algos:
87 return "BLAKE2b-256" 95 return "BLAKE2b-256"
88 if "sha256" in hashlib.algorithms_available: 96 if "sha256" in algos:
89 return "SHA256" 97 return "SHA256"
90 return "SHA1" 98 return "SHA1"
91 99
92 100
93 def get_blake2b(): 101 def get_blake2b():