summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichał Górny <mgorny@gentoo.org>2017-10-22 16:51:16 +0200
committerMichał Górny <mgorny@gentoo.org>2017-10-22 16:51:16 +0200
commit9d2d1c85adf1a00f8774b1e59d8b5269fe81f309 (patch)
tree0a8f9e00912cfd70f74446633546a75cc2af2497
parenta57c8f61591d3d9041c1eab356c397b9891f5ba4 (diff)
downloadgemato-9d2d1c85adf1a00f8774b1e59d8b5269fe81f309.tar.gz
hash: Support pyblake2 & pysha3 fallbacks
-rw-r--r--gemato/hash.py22
-rw-r--r--tox.ini28
2 files changed, 50 insertions, 0 deletions
diff --git a/gemato/hash.py b/gemato/hash.py
index 7247ace..6a1c854 100644
--- a/gemato/hash.py
+++ b/gemato/hash.py
@@ -24,6 +24,28 @@ def get_hash_by_name(name):
try:
return hashlib.new(name)
except ValueError:
+ # fallback support
+ if name.startswith('sha3_'):
+ try:
+ import sha3
+ except ImportError:
+ pass
+ else:
+ try:
+ return getattr(sha3, name)()
+ except AttributeError:
+ pass
+ elif name.startswith('blake2'):
+ try:
+ import pyblake2
+ except ImportError:
+ pass
+ else:
+ try:
+ return getattr(pyblake2, name)()
+ except AttributeError:
+ pass
+
raise UnsupportedHash(name)
diff --git a/tox.ini b/tox.ini
index c62895a..1f444a0 100644
--- a/tox.ini
+++ b/tox.ini
@@ -1,5 +1,33 @@
[tox]
envlist = py27,py34,py35,py36,pypy,pypy3
+[testenv:py27]
+deps =
+ pyblake2
+ pysha3
+
+[testenv:py34]
+deps =
+ pyblake2
+ pysha3
+
+[testenv:py35]
+deps =
+ pyblake2
+ pysha3
+
+[testenv:py36]
+# blake2 & sha3 are built-in
+deps =
+
+[testenv:pypy]
+deps =
+ pyblake2
+ pysha3
+
+[testenv:pypy3]
+# note: pyblake2, pysha3 don't build
+deps =
+
[testenv]
commands = python -m unittest discover -v