This repository has been archived on 2024-12-08. You can view files and clone it, but cannot push or open issues or pull requests.
PyBitmessage-2024-12-08/src/fallback/__init__.py
Lee Miller 3be996eb64
Replace obsolete pycrypto with pycryptodome to support jammy:
pycrypto fails to install, openssl 3 has no ripemd160 hash.
Also skip test_crypto.TestHashlib if openssl 3 is found.
2022-05-30 21:32:56 +03:00

33 lines
777 B
Python

"""
Fallback expressions help PyBitmessage modules to run without some external
dependencies.
RIPEMD160Hash
-------------
We need to check :mod:`hashlib` for RIPEMD-160, as it won't be available
if OpenSSL is not linked against or the linked OpenSSL has RIPEMD disabled.
Try to use `pycryptodome <https://pypi.org/project/pycryptodome/>`_
in that case.
"""
import hashlib
try:
hashlib.new('ripemd160')
except ValueError:
try:
from Crypto.Hash import RIPEMD160
except ImportError:
RIPEMD160Hash = None
else:
RIPEMD160Hash = RIPEMD160.new
else:
def RIPEMD160Hash(data=None):
"""hashlib based RIPEMD160Hash"""
hasher = hashlib.new('ripemd160')
if data:
hasher.update(data)
return hasher