1

According to the Python documentation, only a few hash algorithms are guaranteed to be supported by the hashlib module (MD5 and SHA***). How would I go about detecting if other algorithms are available? (like RIPEMD-160) Of course, I could try to use it using the RIPEMD-160 example from the documentation, but I'm not sure how it would complain. Would it throw an exception, if yes, which exception?

cgt
  • 526
  • 6
  • 18

1 Answers1

4

Just try it in a shell:

>>> h = hashlib.new('ripemd161')                                                                                                                     
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/hashlib.py", line 124, in __hash_new
    return __get_builtin_constructor(name)(string)
  File "/usr/lib/python2.7/hashlib.py", line 91, in __get_builtin_constructor
    raise ValueError('unsupported hash type %s' % name)
ValueError: unsupported hash type ripemd161
AdamKG
  • 13,678
  • 3
  • 38
  • 46
  • 1
    Thanks, this is exactly what I wanted. My problem is that RIPEMD-160 _is_ available on my system, so I didn't know which exception it would throw. Now I do, thanks! Will mark as answer when timer is up. – cgt Mar 14 '12 at 16:08