From 3721bf9f6b19ceaae75454956571c33caf5f1e87 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Sat, 11 Feb 2017 04:02:20 +0000 Subject: Implement XEP-0300 (Use of Cryptographic Hash Functions in XMPP) This is used to provide hash agility support and let other XEPs select which hash function they support. --- slixmpp/plugins/xep_0300/stanza.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 slixmpp/plugins/xep_0300/stanza.py (limited to 'slixmpp/plugins/xep_0300/stanza.py') diff --git a/slixmpp/plugins/xep_0300/stanza.py b/slixmpp/plugins/xep_0300/stanza.py new file mode 100644 index 00000000..f5ab483c --- /dev/null +++ b/slixmpp/plugins/xep_0300/stanza.py @@ -0,0 +1,35 @@ +""" + Slixmpp: The Slick XMPP Library + Copyright (C) 2017 Emmanuel Gil Peyrot + This file is part of Slixmpp. + + See the file LICENSE for copying permission. +""" + +from slixmpp.xmlstream import ElementBase + + +class Hash(ElementBase): + name = 'hash' + namespace = 'urn:xmpp:hashes:2' + plugin_attrib = 'hash' + interfaces = {'algo', 'value'} + + allowed_algos = ['sha-1', 'sha-256', 'sha-512', 'sha3-256', 'sha3-512', 'BLAKE2b256', 'BLAKE2b512'] + + def set_algo(self, value): + if value in self.allowed_algos: + self._set_attr('algo', value) + elif value in [None, '']: + self._del_attr('algo') + else: + raise ValueError('Invalid algo: %s' % value) + + def get_value(self): + return self.xml.text + + def set_value(self, value): + self.xml.text = value + + def del_value(self): + self.xml.text = '' -- cgit v1.2.3