Skip to content

Exceptions

Every failure in the package raises a subclass of CryptographyManagerError, which the workflow maps onto a status and an HTTP code. The one exception is BackendImportError, raised when an optional backend is unavailable.

exceptions

Custom exceptions for the Cryptography Manager.

This module defines all custom exceptions used throughout the library, providing clear error handling and debugging information.

BackendImportError

Bases: Exception

Raised when an optional cryptographic backend cannot be imported.

Deliberately not named ImportError: shadowing the builtin makes except ImportError inside this package silently stop catching real import failures.

CryptographyManagerError

CryptographyManagerError(
    message: str, error_code: str | None = None
)

Bases: Exception

Base exception for all Cryptography Manager errors.

Initialize the base exception.

Parameters:

Name Type Description Default
message str

Human-readable error message

required
error_code str | None

Optional error code for programmatic handling

None
Source code in src/cryptography_manager/exceptions.py
def __init__(self, message: str, error_code: str | None = None) -> None:
    """Initialize the base exception.

    Args:
        message: Human-readable error message
        error_code: Optional error code for programmatic handling
    """
    super().__init__(message)
    self.message = message
    self.error_code = error_code

OperationNotImplementedError

OperationNotImplementedError(
    message: str,
    operation: str | None = None,
    error_code: str | None = None,
)

Bases: CryptographyManagerError

Raised for a recognised operation that has no adapter yet.

Distinct from an unknown operation: the request was well-formed and names something the component intends to support, so the caller should be told "not yet" rather than "no such thing".

Initialize the not-implemented error.

Parameters:

Name Type Description Default
message str

Human-readable error message

required
operation str | None

The operation that is not yet available

None
error_code str | None

Optional error code for programmatic handling

None
Source code in src/cryptography_manager/exceptions.py
def __init__(
    self,
    message: str,
    operation: str | None = None,
    error_code: str | None = None,
) -> None:
    """Initialize the not-implemented error.

    Args:
        message: Human-readable error message
        operation: The operation that is not yet available
        error_code: Optional error code for programmatic handling
    """
    super().__init__(message, error_code)
    self.operation = operation

ConfigurationError

ConfigurationError(
    message: str,
    config_key: str | None = None,
    error_code: str | None = None,
)

Bases: CryptographyManagerError

Raised when there are configuration-related errors.

Initialize configuration error.

Parameters:

Name Type Description Default
message str

Human-readable error message

required
config_key str | None

The configuration key that caused the error

None
error_code str | None

Optional error code for programmatic handling

None
Source code in src/cryptography_manager/exceptions.py
def __init__(
    self,
    message: str,
    config_key: str | None = None,
    error_code: str | None = None,
) -> None:
    """Initialize configuration error.

    Args:
        message: Human-readable error message
        config_key: The configuration key that caused the error
        error_code: Optional error code for programmatic handling
    """
    super().__init__(message, error_code)
    self.config_key = config_key

AdapterError

AdapterError(
    message: str,
    adapter_name: str | None = None,
    operation: str | None = None,
    error_code: str | None = None,
)

Bases: CryptographyManagerError

Raised when there are adapter-related errors.

Initialize adapter error.

Parameters:

Name Type Description Default
message str

Human-readable error message

required
adapter_name str | None

Name of the adapter that caused the error

None
operation str | None

The operation that failed

None
error_code str | None

Optional error code for programmatic handling

None
Source code in src/cryptography_manager/exceptions.py
def __init__(
    self,
    message: str,
    adapter_name: str | None = None,
    operation: str | None = None,
    error_code: str | None = None,
) -> None:
    """Initialize adapter error.

    Args:
        message: Human-readable error message
        adapter_name: Name of the adapter that caused the error
        operation: The operation that failed
        error_code: Optional error code for programmatic handling
    """
    super().__init__(message, error_code)
    self.adapter_name = adapter_name
    self.operation = operation

KeyManagementError

KeyManagementError(
    message: str,
    key_id: str | None = None,
    operation: str | None = None,
    error_code: str | None = None,
)

Bases: CryptographyManagerError

Raised when there are key management-related errors.

Initialize key management error.

Parameters:

Name Type Description Default
message str

Human-readable error message

required
key_id str | None

ID of the key that caused the error

None
operation str | None

The key operation that failed

None
error_code str | None

Optional error code for programmatic handling

None
Source code in src/cryptography_manager/exceptions.py
def __init__(
    self,
    message: str,
    key_id: str | None = None,
    operation: str | None = None,
    error_code: str | None = None,
) -> None:
    """Initialize key management error.

    Args:
        message: Human-readable error message
        key_id: ID of the key that caused the error
        operation: The key operation that failed
        error_code: Optional error code for programmatic handling
    """
    super().__init__(message, error_code)
    self.key_id = key_id
    self.operation = operation

AuditError

AuditError(
    message: str,
    operation: str | None = None,
    error_code: str | None = None,
)

Bases: CryptographyManagerError

Raised when there are audit logging-related errors.

Initialize audit error.

Parameters:

Name Type Description Default
message str

Human-readable error message

required
operation str | None

The operation that failed to be audited

None
error_code str | None

Optional error code for programmatic handling

None
Source code in src/cryptography_manager/exceptions.py
def __init__(
    self,
    message: str,
    operation: str | None = None,
    error_code: str | None = None,
) -> None:
    """Initialize audit error.

    Args:
        message: Human-readable error message
        operation: The operation that failed to be audited
        error_code: Optional error code for programmatic handling
    """
    super().__init__(message, error_code)
    self.operation = operation

HomomorphicEncryptionError

HomomorphicEncryptionError(
    message: str,
    scheme: str | None = None,
    operation: str | None = None,
    error_code: str | None = None,
)

Bases: AdapterError

Raised when there are homomorphic encryption-related errors.

Initialize homomorphic encryption error.

Parameters:

Name Type Description Default
message str

Human-readable error message

required
scheme str | None

The HE scheme that caused the error

None
operation str | None

The HE operation that failed

None
error_code str | None

Optional error code for programmatic handling

None
Source code in src/cryptography_manager/exceptions.py
def __init__(
    self,
    message: str,
    scheme: str | None = None,
    operation: str | None = None,
    error_code: str | None = None,
) -> None:
    """Initialize homomorphic encryption error.

    Args:
        message: Human-readable error message
        scheme: The HE scheme that caused the error
        operation: The HE operation that failed
        error_code: Optional error code for programmatic handling
    """
    super().__init__(
        message, "homomorphic_encryption", operation, error_code
    )
    self.scheme = scheme

SecureMultiPartyComputationError

SecureMultiPartyComputationError(
    message: str,
    protocol: str | None = None,
    operation: str | None = None,
    error_code: str | None = None,
)

Bases: AdapterError

Raised when there are secure multi-party computation-related errors.

Initialize SMPC error.

Parameters:

Name Type Description Default
message str

Human-readable error message

required
protocol str | None

The SMPC protocol that caused the error

None
operation str | None

The SMPC operation that failed

None
error_code str | None

Optional error code for programmatic handling

None
Source code in src/cryptography_manager/exceptions.py
def __init__(
    self,
    message: str,
    protocol: str | None = None,
    operation: str | None = None,
    error_code: str | None = None,
) -> None:
    """Initialize SMPC error.

    Args:
        message: Human-readable error message
        protocol: The SMPC protocol that caused the error
        operation: The SMPC operation that failed
        error_code: Optional error code for programmatic handling
    """
    super().__init__(
        message, "secure_multiparty_computation", operation, error_code
    )
    self.protocol = protocol

DifferentialPrivacyError

DifferentialPrivacyError(
    message: str,
    mechanism: str | None = None,
    operation: str | None = None,
    error_code: str | None = None,
)

Bases: AdapterError

Raised when there are differential privacy-related errors.

Initialize differential privacy error.

Parameters:

Name Type Description Default
message str

Human-readable error message

required
mechanism str | None

The DP mechanism that caused the error

None
operation str | None

The DP operation that failed

None
error_code str | None

Optional error code for programmatic handling

None
Source code in src/cryptography_manager/exceptions.py
def __init__(
    self,
    message: str,
    mechanism: str | None = None,
    operation: str | None = None,
    error_code: str | None = None,
) -> None:
    """Initialize differential privacy error.

    Args:
        message: Human-readable error message
        mechanism: The DP mechanism that caused the error
        operation: The DP operation that failed
        error_code: Optional error code for programmatic handling
    """
    super().__init__(
        message, "differential_privacy", operation, error_code
    )
    self.mechanism = mechanism

StandardCryptographyError

StandardCryptographyError(
    message: str,
    algorithm: str | None = None,
    operation: str | None = None,
    error_code: str | None = None,
)

Bases: AdapterError

Raised when there are standard cryptography-related errors.

Initialize standard cryptography error.

Parameters:

Name Type Description Default
message str

Human-readable error message

required
algorithm str | None

The cryptographic algorithm that caused the error

None
operation str | None

The crypto operation that failed

None
error_code str | None

Optional error code for programmatic handling

None
Source code in src/cryptography_manager/exceptions.py
def __init__(
    self,
    message: str,
    algorithm: str | None = None,
    operation: str | None = None,
    error_code: str | None = None,
) -> None:
    """Initialize standard cryptography error.

    Args:
        message: Human-readable error message
        algorithm: The cryptographic algorithm that caused the error
        operation: The crypto operation that failed
        error_code: Optional error code for programmatic handling
    """
    super().__init__(
        message, "standard_cryptography", operation, error_code
    )
    self.algorithm = algorithm