def _get_digest_algorithm(name = None):
'''
Get the digest algorithm to use based on the settings.
:param name: name of algorithm to use
:type name: str
:return: digest algorithm
:rtype: class
'''
if name:
possible_algorithms = [name.lower()]
else:
possible_algorithms = filter(lambda a: a in hashlib.algorithms_available,
(map(str.lower, settings.ALLOWED_DIGEST_ALGORITHMS)))
for algo_name in possible_algorithms:
if hasattr(hashlib, algo_name):
return getattr(hashlib, algo_name)
logger.error('No algorithm from %r found in hashlib %r',
settings.ALLOWED_DIGEST_ALGORITHMS, hashlib.algorithms_available)
raise exceptions.AlgorithmNotSupported('No suitable algorithm found.')
评论列表
文章目录