xep_0384: Move _generate_encrypted_payload out of plugin class
Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
parent
2891e92269
commit
b64371e8fe
1 changed files with 19 additions and 18 deletions
37
plugin.py
37
plugin.py
|
@ -80,6 +80,24 @@ def _parse_bundle(backend: Backend, bundle: Bundle) -> ExtendedPublicBundle:
|
||||||
return ExtendedPublicBundle.parse(backend, identity_key, spk, spk_signature, otpks)
|
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?
|
# XXX: This should probably be moved in plugins/base.py?
|
||||||
class PluginCouldNotLoad(Exception): pass
|
class PluginCouldNotLoad(Exception): pass
|
||||||
|
|
||||||
|
@ -182,23 +200,6 @@ class XEP_0384(BasePlugin):
|
||||||
|
|
||||||
return iq
|
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:
|
async def _publish_bundle(self) -> None:
|
||||||
if self._omemo.republish_bundle:
|
if self._omemo.republish_bundle:
|
||||||
iq = self._generate_bundle_iq()
|
iq = self._generate_bundle_iq()
|
||||||
|
@ -388,4 +389,4 @@ class XEP_0384(BasePlugin):
|
||||||
bundles,
|
bundles,
|
||||||
always_trust=True,
|
always_trust=True,
|
||||||
)
|
)
|
||||||
return self._generate_encrypted_payload(encrypted)
|
return _generate_encrypted_payload(encrypted)
|
||||||
|
|
Loading…
Reference in a new issue