diff options
author | Robin H. Johnson <robbat2@gentoo.org> | 2017-11-13 08:58:31 -0800 |
---|---|---|
committer | Robin H. Johnson <robbat2@gentoo.org> | 2017-11-13 13:20:36 -0800 |
commit | f754e1d73fad37b3a1ba27de5b49c2902e2f1f23 (patch) | |
tree | b603b61d3a2c22821614f3aaa6cb4883e2488763 | |
parent | 883662241ce7ab45515484e7b53a2e967408d203 (diff) | |
download | gemato-f754e1d73fad37b3a1ba27de5b49c2902e2f1f23.tar.gz |
hash: special cases first, avoid exception.
Handle known special cases for hashes first, to avoid all fallback
cases. Also avoid the ValueError exception if possible, with a simple
conditional.
Signed-off-by: Robin H. Johnson <robbat2@gentoo.org>
-rw-r--r-- | gemato/hash.py | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/gemato/hash.py b/gemato/hash.py index 3b4eb44..b5b57cd 100644 --- a/gemato/hash.py +++ b/gemato/hash.py @@ -34,14 +34,14 @@ def get_hash_by_name(name): Get a hashlib-compatible hash object for hash named @name. Supports multiple backends. """ - try: - return hashlib.new(name) - except ValueError: - pass - + # special case hashes if name == '__size__': return SizeHash() + # general hash support + if name in hashlib.algorithms_available: + return hashlib.new(name) + # fallback support if name.startswith('sha3_'): try: |