diff sat/memory/encryption.py @ 3911:8289ac1b34f4

plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo: - support for both (modern) OMEMO under the `urn:xmpp:omemo:2` namespace and (legacy) OMEMO under the `eu.siacs.conversations.axolotl` namespace - maintains one identity across both versions of OMEMO - migrates data from the old plugin - includes more features for protocol stability - uses SCE for modern OMEMO - fully type-checked, linted and format-checked - added type hints to various pieces of backend code used by the plugin - added stubs for some Twisted APIs used by the plugin under stubs/ (use `export MYPYPATH=stubs/` before running mypy) - core (xmpp): enabled `send` trigger and made it an asyncPoint fix 375
author Syndace <me@syndace.dev>
date Tue, 23 Aug 2022 21:06:24 +0200
parents be6d91572633
children cc2705225778
line wrap: on
line diff
--- a/sat/memory/encryption.py	Thu Sep 22 12:03:12 2022 +0200
+++ b/sat/memory/encryption.py	Tue Aug 23 21:06:24 2022 +0200
@@ -19,10 +19,11 @@
 
 import copy
 from functools import partial
-from collections import namedtuple
+from typing import Optional
 from twisted.words.protocols.jabber import jid
 from twisted.internet import defer
 from twisted.python import failure
+from sat.core.core_types import EncryptionPlugin, EncryptionSession, MessageData
 from sat.core.i18n import D_, _
 from sat.core.constants import Const as C
 from sat.core import exceptions
@@ -34,12 +35,6 @@
 
 log = getLogger(__name__)
 
-EncryptionPlugin = namedtuple("EncryptionPlugin", ("instance",
-                                                   "name",
-                                                   "namespace",
-                                                   "priority",
-                                                   "directed"))
-
 
 class EncryptionHandler:
     """Class to handle encryption sessions for a client"""
@@ -339,7 +334,7 @@
 
         self.client.feedback(entity, msg)
 
-    def getSession(self, entity):
+    def getSession(self, entity: jid.JID) -> Optional[EncryptionSession]:
         """Get encryption session for this contact
 
         @param entity(jid.JID): get the session for this entity
@@ -476,13 +471,17 @@
 
         return mess_data
 
-    def isEncryptionRequested(self, mess_data, namespace=None):
+    def isEncryptionRequested(
+        self,
+        mess_data: MessageData,
+        namespace: Optional[str] = None
+    ) -> bool:
         """Helper method to check if encryption is requested in an outgoind message
 
-        @param mess_data(dict): message data for outgoing message
-        @param namespace(str, None): if set, check if encryption is requested for the
-            algorithm specified
-        @return (bool): True if the encryption flag is present
+        @param mess_data: message data for outgoing message
+        @param namespace: if set, check if encryption is requested for the algorithm
+            specified
+        @return: True if the encryption flag is present
         """
         encryption = mess_data.get(C.MESS_KEY_ENCRYPTION)
         if encryption is None: