comparison sat/memory/encryption.py @ 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 826bca181226
children 2f406b762788
comparison
equal deleted inserted replaced
3216:8418e0c83ed7 3217:0469c53ed5dd
435 @param mess_data(dict): message data as used in post treat workflow 435 @param mess_data(dict): message data as used in post treat workflow
436 """ 436 """
437 mess_data[C.MESS_KEY_ENCRYPTED] = True 437 mess_data[C.MESS_KEY_ENCRYPTED] = True
438 return mess_data 438 return mess_data
439 439
440 def isEncryptionRequested(self, mess_data): 440 def isEncryptionRequested(self, mess_data, namespace=None):
441 """Helper method to check if encryption is requested in an outgoind message 441 """Helper method to check if encryption is requested in an outgoind message
442 442
443 @param mess_data(dict): message data for outgoing message 443 @param mess_data(dict): message data for outgoing message
444 @param namespace(str, None): if set, check if encryption is requested for the
445 algorithm specified
444 @return (bool): True if the encryption flag is present 446 @return (bool): True if the encryption flag is present
445 """ 447 """
446 return bool(mess_data.get(C.MESS_KEY_ENCRYPTION, False)) 448 encryption = mess_data.get(C.MESS_KEY_ENCRYPTION)
449 if encryption is None:
450 return False
451 # we get plugin even if namespace is None to be sure that the key exists
452 plugin = encryption['plugin']
453 if namespace is None:
454 return True
455 return plugin.namespace == namespace
447 456
448 def isEncrypted(self, mess_data): 457 def isEncrypted(self, mess_data):
449 """Helper method to check if an incoming message has the e2e encrypted flag 458 """Helper method to check if an incoming message has the e2e encrypted flag
450 459
451 @param mess_data(dict): message data 460 @param mess_data(dict): message data