Skip to content

AsyncEncryptionKeyStorageStrategy

Interface for async key management strategies used in event encryption.

Async counterpart of EncryptionKeyStorageStrategy. Operations that perform I/O are coroutines. Implementations are responsible for storing, retrieving, and deleting encryption keys for data subjects. Supports multi-tenancy via scoped_for_tenant.

Source code in event_sourcery/_event_store/_async/encryption.py
class AsyncEncryptionKeyStorageStrategy:
    """
    Interface for async key management strategies used in event encryption.

    Async counterpart of `EncryptionKeyStorageStrategy`. Operations that
    perform I/O are coroutines. Implementations are responsible for storing,
    retrieving, and deleting encryption keys for data subjects. Supports
    multi-tenancy via `scoped_for_tenant`.
    """

    async def get(self, subject_id: str) -> bytes | None:
        """
        Retrieves the encryption key for the given subject identifier.

        Args:
            subject_id (str): The subject identifier.

        Returns:
            bytes | None: The encryption key, or None if not found.
        """
        raise NotImplementedError()

    async def store(self, subject_id: str, key: bytes) -> None:
        """
        Stores the encryption key for the given subject identifier.

        Args:
            subject_id (str): The subject identifier.
            key (bytes): The encryption key to store.
        """
        raise NotImplementedError()

    async def delete(self, subject_id: str) -> None:
        """
        Deletes the encryption key for the given subject identifier.

        Args:
            subject_id (str): The subject identifier whose key should be deleted.
        """
        raise NotImplementedError()

    def scoped_for_tenant(self, tenant_id: TenantId) -> Self:
        """
        Returns a key storage strategy instance scoped for the given tenant.

        Args:
            tenant_id (TenantId): The tenant identifier.

        Returns:
            Self: The key storage strategy instance for the tenant.
        """
        raise NotImplementedError()

delete(subject_id) async

Deletes the encryption key for the given subject identifier.

Parameters:

Name Type Description Default
subject_id str

The subject identifier whose key should be deleted.

required
Source code in event_sourcery/_event_store/_async/encryption.py
async def delete(self, subject_id: str) -> None:
    """
    Deletes the encryption key for the given subject identifier.

    Args:
        subject_id (str): The subject identifier whose key should be deleted.
    """
    raise NotImplementedError()

get(subject_id) async

Retrieves the encryption key for the given subject identifier.

Parameters:

Name Type Description Default
subject_id str

The subject identifier.

required

Returns:

Type Description
bytes | None

bytes | None: The encryption key, or None if not found.

Source code in event_sourcery/_event_store/_async/encryption.py
async def get(self, subject_id: str) -> bytes | None:
    """
    Retrieves the encryption key for the given subject identifier.

    Args:
        subject_id (str): The subject identifier.

    Returns:
        bytes | None: The encryption key, or None if not found.
    """
    raise NotImplementedError()

scoped_for_tenant(tenant_id)

Returns a key storage strategy instance scoped for the given tenant.

Parameters:

Name Type Description Default
tenant_id TenantId

The tenant identifier.

required

Returns:

Name Type Description
Self Self

The key storage strategy instance for the tenant.

Source code in event_sourcery/_event_store/_async/encryption.py
def scoped_for_tenant(self, tenant_id: TenantId) -> Self:
    """
    Returns a key storage strategy instance scoped for the given tenant.

    Args:
        tenant_id (TenantId): The tenant identifier.

    Returns:
        Self: The key storage strategy instance for the tenant.
    """
    raise NotImplementedError()

store(subject_id, key) async

Stores the encryption key for the given subject identifier.

Parameters:

Name Type Description Default
subject_id str

The subject identifier.

required
key bytes

The encryption key to store.

required
Source code in event_sourcery/_event_store/_async/encryption.py
async def store(self, subject_id: str, key: bytes) -> None:
    """
    Stores the encryption key for the given subject identifier.

    Args:
        subject_id (str): The subject identifier.
        key (bytes): The encryption key to store.
    """
    raise NotImplementedError()