Add interface semi-hidden to RatchetForwardingMessage

Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
Maxime “pep” Buquet 2021-07-18 00:30:07 +02:00
parent 26665d9e6a
commit 494899bb3c
Signed by: pep
GPG key ID: DEDA74AEECA9D0F2

View file

@ -602,10 +602,11 @@ class XEP_0384(BasePlugin):
"""
msg = self.xmpp.make_message(mto=jid)
encrypted = await self.encrypt_key_transport_message(
encrypted = await self.encrypt_message(
plaintext=None,
recipients=[jid],
expect_problems=None,
_ignore_trust=True,
)
msg.append(encrypted)
return msg
@ -708,21 +709,10 @@ class XEP_0384(BasePlugin):
async def encrypt_message(
self,
plaintext: str,
recipients: List[JID],
expect_problems: Optional[Dict[JID, List[int]]] = None,
) -> Encrypted:
return await self.encrypt_key_transport_message(
plaintext.encode('utf-8'),
recipients,
expect_problems,
)
async def encrypt_key_transport_message(
self,
plaintext: Optional[bytes],
plaintext: Optional[str],
recipients: List[JID],
expect_problems: Optional[Dict[JID, List[int]]] = None,
_ignore_trust: bool = False,
) -> Encrypted:
"""
Returns an encrypted payload to be placed into a message.
@ -730,6 +720,14 @@ class XEP_0384(BasePlugin):
The API for getting an encrypted payload consists of trying first
and fixing errors progressively. The actual sending happens once the
application (us) thinks we're good to go.
If `plaintext` is specified, this will generate a full OMEMO payload. If
not, if `_ignore_trust` is True, this will generate a ratchet forwarding
message, and otherwise it will generate a key transport message.
These are rather technical details to the user and fiddling with
parameters else than `plaintext` and `recipients` should be rarely
needed.
"""
recipients = [jid.bare for jid in recipients]
@ -749,7 +747,13 @@ class XEP_0384(BasePlugin):
if plaintext is not None:
encrypted = self._omemo.encryptMessage(
recipients,
plaintext,
plaintext.encode('utf-8'),
self.bundles,
expect_problems=expect_problems,
)
elif _ignore_trust:
encrypted = self._omemo.encryptRatchetForwardingMessage(
recipients,
self.bundles,
expect_problems=expect_problems,
)