changeset 3217:0469c53ed5dd

core (memory/encryption): namespace can now be specified to test a specific algorithm in isEncryptionRequested
author Goffi <goffi@goffi.org>
date Wed, 18 Mar 2020 19:54:07 +0100
parents 8418e0c83ed7
children 806a7936a591
files sat/memory/encryption.py
diffstat 1 files changed, 11 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/sat/memory/encryption.py	Fri Mar 13 17:50:08 2020 +0100
+++ b/sat/memory/encryption.py	Wed Mar 18 19:54:07 2020 +0100
@@ -437,13 +437,22 @@
         mess_data[C.MESS_KEY_ENCRYPTED] = True
         return mess_data
 
-    def isEncryptionRequested(self, mess_data):
+    def isEncryptionRequested(self, mess_data, namespace=None):
         """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
         """
-        return bool(mess_data.get(C.MESS_KEY_ENCRYPTION, False))
+        encryption = mess_data.get(C.MESS_KEY_ENCRYPTION)
+        if encryption is None:
+            return False
+        # we get plugin even if namespace is None to be sure that the key exists
+        plugin = encryption['plugin']
+        if namespace is None:
+            return True
+        return plugin.namespace == namespace
 
     def isEncrypted(self, mess_data):
         """Helper method to check if an incoming message has the e2e encrypted flag