From 2891e9226988f4ba206125efe1f99820b5b0d328 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:31:37 +0100 Subject: [PATCH] xep_0384: move _parse_bundle 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 27bf58b..d09c6dd 100644 --- a/plugin.py +++ b/plugin.py @@ -62,6 +62,24 @@ def _load_device_id(data_dir: str) -> int: return did +def _parse_bundle(backend: Backend, bundle: Bundle) -> ExtendedPublicBundle: + identity_key = b64dec(bundle['identityKey']['value'].strip()) + spk = { + 'id': int(bundle['signedPreKeyPublic']['signedPreKeyId']), + 'key': b64dec(bundle['signedPreKeyPublic']['value'].strip()), + } + spk_signature = b64dec(bundle['signedPreKeySignature']['value'].strip()) + + otpks = [] + for prekey in bundle['prekeys']: + otpks.append({ + 'id': int(prekey['preKeyId']), + 'key': b64dec(prekey['value'].strip()), + }) + + return ExtendedPublicBundle.parse(backend, identity_key, spk, spk_signature, otpks) + + # XXX: This should probably be moved in plugins/base.py? class PluginCouldNotLoad(Exception): pass @@ -191,24 +209,7 @@ class XEP_0384(BasePlugin): iq = await self.xmpp['xep_0060'].get_items(jid, node) bundle = iq['pubsub']['items']['item']['bundle'] - return self._parse_bundle(self._omemo_backend, bundle) - - def _parse_bundle(self, backend: Backend, bundle: Bundle) -> ExtendedPublicBundle: - ik = b64dec(bundle['identityKey']['value'].strip()) - spk = { - 'id': int(bundle['signedPreKeyPublic']['signedPreKeyId']), - 'key': b64dec(bundle['signedPreKeyPublic']['value'].strip()), - } - spk_signature = b64dec(bundle['signedPreKeySignature']['value'].strip()) - - otpks = [] - for prekey in bundle['prekeys']: - otpks.append({ - 'id': int(prekey['preKeyId']), - 'key': b64dec(prekey['value'].strip()), - }) - - return ExtendedPublicBundle.parse(backend, ik, spk, spk_signature, otpks) + return _parse_bundle(self._omemo_backend, bundle) def _store_device_ids(self, jid: str, items) -> None: device_ids = [] # type: List[int]