Skip to content

EncryptionStrategy

Interface for encryption algorithms used to secure event data.

Implementations should provide methods for encrypting and decrypting data using a given key. Used by the Encryption service to process event fields marked for encryption.

Source code in event_sourcery/_event_store/event/encryption.py
class EncryptionStrategy:
    """
    Interface for encryption algorithms used to secure event data.

    Implementations should provide methods for encrypting and decrypting data using a
    given key.
    Used by the Encryption service to process event fields marked for encryption.
    """

    def encrypt(self, data: Any, key: bytes) -> str:
        """
        Encrypts the given data using the provided key.

        Args:
            data (Any): The data to encrypt.
            key (bytes): The encryption key.

        Returns:
            str: The encrypted data as a string.
        """
        raise NotImplementedError()

    def decrypt(self, data: str, key: bytes) -> Any:
        """
        Decrypts the given data using the provided key.

        Args:
            data (str): The encrypted data as a string.
            key (bytes): The encryption key.

        Returns:
            Any: The decrypted data.
        """
        raise NotImplementedError()

decrypt(data, key)

Decrypts the given data using the provided key.

Parameters:

Name Type Description Default
data str

The encrypted data as a string.

required
key bytes

The encryption key.

required

Returns:

Name Type Description
Any Any

The decrypted data.

Source code in event_sourcery/_event_store/event/encryption.py
def decrypt(self, data: str, key: bytes) -> Any:
    """
    Decrypts the given data using the provided key.

    Args:
        data (str): The encrypted data as a string.
        key (bytes): The encryption key.

    Returns:
        Any: The decrypted data.
    """
    raise NotImplementedError()

encrypt(data, key)

Encrypts the given data using the provided key.

Parameters:

Name Type Description Default
data Any

The data to encrypt.

required
key bytes

The encryption key.

required

Returns:

Name Type Description
str str

The encrypted data as a string.

Source code in event_sourcery/_event_store/event/encryption.py
def encrypt(self, data: Any, key: bytes) -> str:
    """
    Encrypts the given data using the provided key.

    Args:
        data (Any): The data to encrypt.
        key (bytes): The encryption key.

    Returns:
        str: The encrypted data as a string.
    """
    raise NotImplementedError()