summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmmanuel Gil Peyrot <linkmauve@linkmauve.fr>2017-02-11 23:30:43 +0000
committerEmmanuel Gil Peyrot <linkmauve@linkmauve.fr>2017-02-11 23:30:43 +0000
commit59dad12820733de4e6b92082404e1726aaef19f8 (patch)
tree0cf5828f3f759dddea3385ff1a17248803378229
parent007c8362967d22850f7cce2cfdb3c83e6c69fbf2 (diff)
downloadslixmpp-59dad12820733de4e6b92082404e1726aaef19f8.tar.gz
slixmpp-59dad12820733de4e6b92082404e1726aaef19f8.tar.bz2
slixmpp-59dad12820733de4e6b92082404e1726aaef19f8.tar.xz
slixmpp-59dad12820733de4e6b92082404e1726aaef19f8.zip
XEP-0300: Workaround for Python 3.5 or below.
-rw-r--r--slixmpp/plugins/xep_0300/hash.py13
1 files changed, 10 insertions, 3 deletions
diff --git a/slixmpp/plugins/xep_0300/hash.py b/slixmpp/plugins/xep_0300/hash.py
index 0c71aac1..43dcb5bd 100644
--- a/slixmpp/plugins/xep_0300/hash.py
+++ b/slixmpp/plugins/xep_0300/hash.py
@@ -39,8 +39,8 @@ class XEP_0300(BasePlugin):
'sha-1': hashlib.sha1,
'sha-256': hashlib.sha256,
'sha-512': hashlib.sha512,
- 'sha3-256': hashlib.sha3_256,
- 'sha3-512': hashlib.sha3_512,
+ 'sha3-256': lambda: hashlib.sha3_256(),
+ 'sha3-512': lambda: hashlib.sha3_512(),
'BLAKE2b256': lambda: hashlib.blake2b(digest_size=32),
'BLAKE2b512': lambda: hashlib.blake2b(digest_size=64),
}
@@ -50,7 +50,14 @@ class XEP_0300(BasePlugin):
self.enabled_hashes = []
for algo in self._hashlib_function:
if getattr(self, 'enable_' + algo, False):
- self.enabled_hashes.append(namespace % algo)
+ # XXX: this is a hack for Python 3.5 or below, which
+ # don’t support sha3 or blake2b…
+ try:
+ self._hashlib_function[algo]()
+ except AttributeError:
+ log.warn('Algorithm %s unavailable, disabling.', algo)
+ else:
+ self.enabled_hashes.append(namespace % algo)
def session_bind(self, jid):
self.xmpp['xep_0030'].add_feature(Hash.namespace)