/ src / fallback / __init__.py
__init__.py
 1  """
 2  Fallback expressions help PyBitmessage modules to run without some external
 3  dependencies.
 4  
 5  
 6  RIPEMD160Hash
 7  -------------
 8  
 9  We need to check :mod:`hashlib` for RIPEMD-160, as it won't be available
10  if OpenSSL is not linked against or the linked OpenSSL has RIPEMD disabled.
11  Try to use `pycryptodome <https://pypi.org/project/pycryptodome/>`_
12  in that case.
13  """
14  
15  import hashlib
16  
17  try:
18      hashlib.new('ripemd160')
19  except ValueError:
20      try:
21          from Crypto.Hash import RIPEMD160
22      except ImportError:
23          RIPEMD160Hash = None
24      else:
25          RIPEMD160Hash = RIPEMD160.new
26  else:
27      def RIPEMD160Hash(data=None):
28          """hashlib based RIPEMD160Hash"""
29          hasher = hashlib.new('ripemd160')
30          if data:
31              hasher.update(data)
32          return hasher