Skip to content

Mixin

Mixin implementation of encryption capability with common encryption logic.

Authors

Kadek Denaya (kadek.d.r.diana@gdplabs.id)

References

NONE

EncryptionCapabilityMixin(encryptor, encrypted_fields)

Mixin implementation of EncryptionCapability with common encryption logic.

This class provides the shared encryption and decryption logic that is identical across all backend implementations. Backend-specific encryption capabilities should inherit from this class and add backend-specific initialization.

Attributes:

Name Type Description
encryptor BaseEncryptor

The encryptor instance to use for encryption/decryption.

Initialize the encryption capability mixin.

Parameters:

Name Type Description Default
encryptor BaseEncryptor

The encryptor instance to use for encryption.

required
encrypted_fields set[str]

The set of fields to encrypt. Supports: 1. Content field: "content" 2. Metadata fields using dot notation: "metadata.secret_key", "metadata.secret_value" Example: {"content", "metadata.secret_key", "metadata.secret_value"}

required

encryption_config property

Get the current encryption configuration.

Returns:

Type Description
set[str] | None

set[str] | None: Set of encrypted field names.

decrypt_chunks(chunks, logger=None)

Decrypt chunks if encryption is enabled.

Parameters:

Name Type Description Default
chunks list[Chunk]

List of chunks to decrypt.

required
logger Any | None

Optional logger instance for logging operations. Defaults to None.

None

Returns:

Type Description
list[Chunk]

list[Chunk]: List of decrypted chunks.

encrypt_chunks(chunks, logger=None)

Encrypt chunks if encryption is enabled.

Parameters:

Name Type Description Default
chunks list[Chunk]

List of chunks to encrypt.

required
logger Any | None

Optional logger instance for logging operations. Defaults to None.

None

Returns:

Type Description
list[Chunk]

list[Chunk]: List of encrypted chunks.