From b64371e8fe29bc79a24edb7fb798b47c79571259 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Sat, 29 Dec 2018 07:34:52 +0100 Subject: [PATCH] xep_0384: Move _generate_encrypted_payload out of plugin class MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- plugin.py | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/plugin.py b/plugin.py index d09c6dd..8f045c3 100644 --- a/plugin.py +++ b/plugin.py @@ -80,6 +80,24 @@ def _parse_bundle(backend: Backend, bundle: Bundle) -> ExtendedPublicBundle: return ExtendedPublicBundle.parse(backend, identity_key, spk, spk_signature, otpks) +def _generate_encrypted_payload(encrypted) -> Encrypted: + tag = Encrypted() + + tag['header']['sid'] = str(encrypted['sid']) + tag['header']['iv']['value'] = b64enc(encrypted['iv']) + tag['payload']['value'] = b64enc(encrypted['payload']) + + for message in encrypted['messages']: + key = Key() + key['value'] = b64enc(message['message']) + key['rid'] = str(message['rid']) + if message['pre_key']: + key['prekey'] = '1' + tag['header'].append(key) + + return tag + + # XXX: This should probably be moved in plugins/base.py? class PluginCouldNotLoad(Exception): pass @@ -182,23 +200,6 @@ class XEP_0384(BasePlugin): return iq - def _generate_encrypted_payload(self, encrypted) -> Encrypted: - tag = Encrypted() - - tag['header']['sid'] = str(encrypted['sid']) - tag['header']['iv']['value'] = b64enc(encrypted['iv']) - tag['payload']['value'] = b64enc(encrypted['payload']) - - for message in encrypted['messages']: - key = Key() - key['value'] = b64enc(message['message']) - key['rid'] = str(message['rid']) - if message['pre_key']: - key['prekey'] = '1' - tag['header'].append(key) - - return tag - async def _publish_bundle(self) -> None: if self._omemo.republish_bundle: iq = self._generate_bundle_iq() @@ -388,4 +389,4 @@ class XEP_0384(BasePlugin): bundles, always_trust=True, ) - return self._generate_encrypted_payload(encrypted) + return _generate_encrypted_payload(encrypted)