comparison sat/memory/encryption.py @ 3228:cc3fea71c365

core (memory/encryption): set encrypted flag also for outgoing messages and put it in extra: - `encrypted` flag is now put directly in extra, so that there is nothing to change when sending the message to bridge for frontends to be aware of it. - this flag is now also set when markAsEncrypted is used, so frontend can display appropriate indicator to show that outgoing message is encrypted or not.
author Goffi <goffi@goffi.org>
date Mon, 23 Mar 2020 16:53:03 +0100
parents 2f406b762788
children e756e0eb1be4
comparison
equal deleted inserted replaced
3227:6d19a99172d7 3228:cc3fea71c365
445 if mess_data["type"] == "groupchat" and encryption['plugin'].directed: 445 if mess_data["type"] == "groupchat" and encryption['plugin'].directed:
446 raise exceptions.InternalError( 446 raise exceptions.InternalError(
447 f"encryption flag must not be set for groupchat if encryption algorithm " 447 f"encryption flag must not be set for groupchat if encryption algorithm "
448 f"({encryption['plugin'].name}) is directed!") 448 f"({encryption['plugin'].name}) is directed!")
449 mess_data[C.MESS_KEY_ENCRYPTION] = encryption 449 mess_data[C.MESS_KEY_ENCRYPTION] = encryption
450 self.markAsEncrypted(mess_data)
450 451
451 ## Misc ## 452 ## Misc ##
452 453
453 def markAsEncrypted(self, mess_data): 454 def markAsEncrypted(self, mess_data):
454 """Helper method to mark a message as having been e2e encrypted. 455 """Helper method to mark a message as having been e2e encrypted.
455 456
456 This should be used in the post_treat workflow of messageReceived trigger of 457 This should be used in the post_treat workflow of messageReceived trigger of
457 the plugin 458 the plugin
458 @param mess_data(dict): message data as used in post treat workflow 459 @param mess_data(dict): message data as used in post treat workflow
459 """ 460 """
460 mess_data[C.MESS_KEY_ENCRYPTED] = True 461 mess_data['extra'][C.MESS_KEY_ENCRYPTED] = True
461 return mess_data 462 return mess_data
462 463
463 def isEncryptionRequested(self, mess_data, namespace=None): 464 def isEncryptionRequested(self, mess_data, namespace=None):
464 """Helper method to check if encryption is requested in an outgoind message 465 """Helper method to check if encryption is requested in an outgoind message
465 466
476 if namespace is None: 477 if namespace is None:
477 return True 478 return True
478 return plugin.namespace == namespace 479 return plugin.namespace == namespace
479 480
480 def isEncrypted(self, mess_data): 481 def isEncrypted(self, mess_data):
481 """Helper method to check if an incoming message has the e2e encrypted flag 482 """Helper method to check if a message has the e2e encrypted flag
482 483
483 @param mess_data(dict): message data 484 @param mess_data(dict): message data
484 @return (bool): True if the encrypted flag is present 485 @return (bool): True if the encrypted flag is present
485 """ 486 """
486 return mess_data.get(C.MESS_KEY_ENCRYPTED, False) 487 return mess_data['extra'].get(C.MESS_KEY_ENCRYPTED, False)
487 488
488 489
489 def markAsTrusted(self, mess_data): 490 def markAsTrusted(self, mess_data):
490 """Helper methor to mark a message as sent from a trusted entity. 491 """Helper methor to mark a message as sent from a trusted entity.
491 492