slixmpp-omemo/slixmpp_omemo/stanza.py

195 lines
4.2 KiB
Python
Raw Permalink Normal View History

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
2018-05-11 01:51:37 +00:00
"""
Slixmpp OMEMO plugin
2018-05-11 01:51:37 +00:00
Copyright (C) 2018 Maxime pep Buquet <pep@bouah.net>
This file is part of slixmpp-omemo.
2018-05-11 01:51:37 +00:00
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
plugin_multi_attrib = 'devices'
2018-05-11 01:51:37 +00:00
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', 'value'}
def get_value(self):
return self.xml.text
def set_value(self, value):
self.xml.text = str(value)
def del_value(self):
self.xml.text = ''
2018-05-11 01:59:32 +00:00
class IV(ElementBase):
namespace = OMEMO_BASE_NS
name = 'iv'
plugin_attrib = name
interfaces = {'value'}
def get_value(self):
return self.xml.text
def set_value(self, value):
self.xml.text = str(value)
def del_value(self):
self.xml.text = ''
2018-05-11 01:59:32 +00:00
class Payload(ElementBase):
namespace = OMEMO_BASE_NS
name = 'payload'
plugin_attrib = name
interfaces = {'value'}
def get_value(self):
return self.xml.text
def set_value(self, value):
self.xml.text = str(value)
def del_value(self):
self.xml.text = ''
2018-05-11 01:59:32 +00:00
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):
2018-05-14 09:09:08 +00:00
self.xml.text = str(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):
2018-05-14 09:09:08 +00:00
self.xml.text = str(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):
2018-05-14 09:09:08 +00:00
self.xml.text = str(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-14 09:09:29 +00:00
plugin_multi_attrib = 'prekeys'
interfaces = {'preKeyId', 'value'}
def get_value(self):
return self.xml.text
def set_value(self, value):
self.xml.text = str(value)
def del_value(self):
self.xml.text = ''
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(Item, Devices)
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)