summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmmanuel Gil Peyrot <linkmauve@linkmauve.fr>2020-12-05 01:00:52 +0100
committerEmmanuel Gil Peyrot <linkmauve@linkmauve.fr>2020-12-05 01:00:52 +0100
commit6db5bb65d337ebc0813a46420dbd8c7dacec74d8 (patch)
tree4e44e2eaef27072c58d6c2ca5a75819f6f2f0270
parentcc96e4a6e727c293e9baee28be287b25649473e0 (diff)
downloadslixmpp-6db5bb65d337ebc0813a46420dbd8c7dacec74d8.tar.gz
slixmpp-6db5bb65d337ebc0813a46420dbd8c7dacec74d8.tar.bz2
slixmpp-6db5bb65d337ebc0813a46420dbd8c7dacec74d8.tar.xz
slixmpp-6db5bb65d337ebc0813a46420dbd8c7dacec74d8.zip
XEP-0300: Fix tests
-rw-r--r--slixmpp/plugins/xep_0300/hash.py20
1 files changed, 9 insertions, 11 deletions
diff --git a/slixmpp/plugins/xep_0300/hash.py b/slixmpp/plugins/xep_0300/hash.py
index 6095671d..75252d0c 100644
--- a/slixmpp/plugins/xep_0300/hash.py
+++ b/slixmpp/plugins/xep_0300/hash.py
@@ -39,25 +39,22 @@ class XEP_0300(BasePlugin):
'sha-1': hashlib.sha1,
'sha-256': hashlib.sha256,
'sha-512': hashlib.sha512,
- 'sha3-256': lambda: hashlib.sha3_256(),
- 'sha3-512': lambda: hashlib.sha3_512(),
+ 'sha3-256': hashlib.sha3_256,
+ 'sha3-512': hashlib.sha3_512,
'BLAKE2b256': lambda: hashlib.blake2b(digest_size=32),
'BLAKE2b512': lambda: hashlib.blake2b(digest_size=64),
}
+ def __init__(self, *args, **kwargs):
+ super().__init__(*args, **kwargs)
+ self.enabled_hashes = []
+
def plugin_init(self):
namespace = 'urn:xmpp:hash-function-text-names:%s'
- self.enabled_hashes = []
+ self.enabled_hashes.clear()
for algo in self._hashlib_function:
if getattr(self, 'enable_' + algo, False):
- # 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)
+ self.enabled_hashes.append(namespace % algo)
def session_bind(self, jid):
self.xmpp['xep_0030'].add_feature(Hash.namespace)
@@ -68,6 +65,7 @@ class XEP_0300(BasePlugin):
def plugin_end(self):
for namespace in self.enabled_hashes:
self.xmpp['xep_0030'].del_feature(namespace)
+ self.enabled_hashes.clear()
self.xmpp['xep_0030'].del_feature(feature=Hash.namespace)