slixmpp-omemo/stanza.py

152 lines
3.4 KiB
Python
Raw Normal View History

2018-05-11 01:51:37 +00:00
"""
Slixmpp: The Slick XMPP Library
Copyright (C) 2018 Maxime pep Buquet <pep@bouah.net>
This file is part of Slixmpp.
See the file LICENSE for copying permission.
"""
from slixmpp import Message
from slixmpp.plugins.xep_0060.stanza.pubsub import Item
2018-05-11 01:51:37 +00:00
from slixmpp.plugins.xep_0060.stanza.pubsub_event import EventItem
from slixmpp.xmlstream import register_stanza_plugin, ElementBase
OMEMO_BASE_NS = 'eu.siacs.conversations.axolotl'
OMEMO_DEVICES_NS = OMEMO_BASE_NS + '.devicelist'
2018-05-14 08:57:30 +00:00
OMEMO_BUNDLES_NS = OMEMO_BASE_NS + '.bundles'
2018-05-11 01:51:37 +00:00
class Devices(ElementBase):
2018-05-11 01:51:37 +00:00
namespace = OMEMO_BASE_NS
name = 'list'
plugin_attrib = 'devices'
2018-05-11 01:51:37 +00:00
interfaces = set()
class Device(ElementBase):
namespace = OMEMO_BASE_NS
name = 'device'
plugin_attrib = name
interfaces = {'id'}
2018-05-11 01:59:32 +00:00
class Encrypted(ElementBase):
namespace = OMEMO_BASE_NS
name = 'encrypted'
plugin_attrib = 'omemo_encrypted'
interfaces = set()
class Header(ElementBase):
namespace = OMEMO_BASE_NS
name = 'header'
plugin_attrib = name
interfaces = {'sid'}
class Key(ElementBase):
namespace = OMEMO_BASE_NS
name = 'key'
plugin_attrib = name
interfaces = {'rid', 'prekey'}
class IV(ElementBase):
namespace = OMEMO_BASE_NS
name = 'iv'
plugin_attrib = name
interfaces = set()
class Payload(ElementBase):
namespace = OMEMO_BASE_NS
name = 'payload'
plugin_attrib = name
interfaces = set()
2018-05-11 02:01:05 +00:00
class Bundle(ElementBase):
namespace = OMEMO_BASE_NS
name = 'bundle'
plugin_attrib = name
interfaces = set()
class SignedPreKeyPublic(ElementBase):
namespace = OMEMO_BASE_NS
name = 'signedPreKeyPublic'
plugin_attrib = name
interfaces = {'signedPreKeyId', '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 = ''
2018-05-11 02:01:05 +00:00
class SignedPreKeySignature(ElementBase):
namespace = OMEMO_BASE_NS
name = 'signedPreKeySignature'
plugin_attrib = name
interfaces = {'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 = ''
2018-05-11 02:01:05 +00:00
class IdentityKey(ElementBase):
namespace = OMEMO_BASE_NS
name = 'identityKey'
plugin_attrib = name
interfaces = {'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 = ''
2018-05-11 02:01:05 +00:00
class PreKeys(ElementBase):
namespace = OMEMO_BASE_NS
name = 'prekeys'
plugin_attrib = name
interfaces = set()
class PreKeyPublic(ElementBase):
namespace = OMEMO_BASE_NS
name = 'preKeyPublic'
plugin_attrib = name
2018-05-13 12:25:19 +00:00
interfaces = {'preKeyId'}
2018-05-11 02:01:05 +00:00
2018-05-11 01:59:32 +00:00
register_stanza_plugin(Message, Encrypted)
register_stanza_plugin(Encrypted, Header)
register_stanza_plugin(Header, Key)
register_stanza_plugin(Header, IV)
register_stanza_plugin(Encrypted, Payload)
register_stanza_plugin(EventItem, Devices)
register_stanza_plugin(Devices, Device, iterable=True)
2018-05-11 02:01:05 +00:00
register_stanza_plugin(Item, Bundle)
2018-05-11 02:01:05 +00:00
register_stanza_plugin(Bundle, SignedPreKeyPublic)
register_stanza_plugin(Bundle, SignedPreKeySignature)
register_stanza_plugin(Bundle, IdentityKey)
register_stanza_plugin(Bundle, PreKeys)
register_stanza_plugin(PreKeys, PreKeyPublic, iterable=True)