diff --git a/monkey/monkey_island/cc/repository/agent_event_encryption.py b/monkey/monkey_island/cc/repository/agent_event_encryption.py index 83469613a..dd0d813cf 100644 --- a/monkey/monkey_island/cc/repository/agent_event_encryption.py +++ b/monkey/monkey_island/cc/repository/agent_event_encryption.py @@ -8,6 +8,9 @@ ENCRYPTED_PREFIX = "encrypted_" def get_fields_to_encrypt(event: AbstractAgentEvent): + """ + Get the fields of the event that are not part of the base AbstractAgentEvent. + """ return set(vars(AbstractAgentEvent)["__fields__"].keys()) ^ set(event.dict().keys()) @@ -16,6 +19,18 @@ def encrypt_event( event_data: JSONSerializable, fields: Iterable[str] = [], ) -> JSONSerializable: + """ + Encrypt a serialized AbstractAgentEvent + + The data is expected to be a dict. The encrypted fields will be given the + prefix "encrypted_". + + :param encrypt: Callable used to encrypt data + :param event_data: Serialized event to encrypt + :param fields: Fields to encrypt + :return: Serialized event with the fields encrypted + :raises TypeError: If the serialized data is not a dict + """ if not isinstance(event_data, dict): raise TypeError("Event encryption only supported for dict") @@ -31,6 +46,14 @@ def encrypt_event( def decrypt_event( decrypt: Callable[[bytes], bytes], event_data: JSONSerializable ) -> JSONSerializable: + """ + Decrypt a serialized AbstractEventData + + :param encrypt: Callable used to decrypt data + :param event_data: Serialized event to decrypt + :return: Serialized event with the fields decrypted + :raises TypeError: If the serialized data is not a dict + """ if not isinstance(event_data, dict): raise TypeError("Event decryption only supported for dict")