Errors¶
Every failure is a subclass of CryptographySuiteError with a stable
ErrorCode. Programs branch on the code, never on the message. Messages are
fixed per code and never contain paths, key material, plaintext, context
values, or text from a key service.
from cryptography_suite import (
AuthenticationError,
ContextMismatchError,
CryptographySuiteError,
EncryptionContext,
Envelope,
ErrorCode,
Policy,
Protector,
)
from cryptography_suite.providers.hpke import HpkeRecipientProvider, generate_private_key
provider = HpkeRecipientProvider()
key = provider.add_identity("k", generate_private_key())
protector = Protector(provider=provider, policy=Policy(), primary_key=key)
try:
protector.open(Envelope(b"not an envelope"), context=EncryptionContext())
except (AuthenticationError, ContextMismatchError):
raise # tampering or the wrong context: alert, do not retry
except CryptographySuiteError as error:
assert error.code is ErrorCode.FORMAT_INVALID
print(error, error.retryable) # The envelope format is invalid. False
retryable is True only for transient key-service failures. The SDK has
already retried those within the policy’s budget before raising, so retrying
again belongs in a job queue with backoff, not in a tight loop. details
holds at most a retry count and an HTTP status code; every other value is
redacted.
Codes¶
Code |
Class |
CLI exit |
Meaning |
What to do |
|---|---|---|---|---|
|
|
3 |
Not a well-formed envelope, or truncated. |
Check that the right bytes were stored and read back completely. |
|
|
3 |
A version, profile, flag, or suite this reader does not support. |
Upgrade the reader. |
|
|
3 |
A size or count above the policy’s limit. |
Use streaming, or raise the limit in the policy. |
|
|
3 |
The envelope requires a feature this reader lacks. |
Upgrade the reader. |
|
|
3 |
Bytes after the final record. |
Treat as tampering or a storage error. |
|
|
4 |
The envelope was changed, or no trusted key opens it correctly. |
Treat as tampering or corruption. Never retry. |
|
|
4 |
The context differs from the one sealed. Same message as an authentication failure. |
Check the context the caller supplies. |
|
|
2 |
A policy or configuration is invalid, such as an enterprise policy without an audit sink. |
Fix the configuration. |
|
|
5 |
The policy forbids the operation: a provider, an algorithm, a missing context key, or a migration without a confirmed backup. |
Fix the request or the policy. |
|
|
5 |
The key version is disabled or destroyed. |
When opening, another recipient is tried first. Re-enable the key or recover from escrow. |
|
|
5 |
The policy does not permit migrating this v3 format, or an unencrypted v3 private key without |
Use |
|
|
7 |
The key service failed or returned something unexpected. |
Retried automatically when transient. Check the service. |
|
|
7 |
The operation’s deadline passed. |
Retried automatically. Check latency and |
|
|
7 |
The key service throttled the request. |
Retried automatically. Raise the quota, or use hierarchical keys. |
|
|
6 |
The key service refused the caller’s credentials or permissions. |
Check credentials and key permissions. |
|
|
6 |
No recipient names a trusted key, or the key does not exist. |
Add the key to the |
|
|
6 |
The key service answered for a different version than requested. |
Check the key configuration. |
|
|
6 |
The key cannot do this: wrap with a public-only key, a wrong key type (including a v3 key an HPKE recipient cannot use), quorum shares still missing. |
Use a key with the capability. |
|
|
10 |
The migrated envelope did not reopen to the same plaintext; nothing was published. |
Check that the protector can open what it seals, and report it. |
|
|
10 |
Reserved for a resumable migration store (RFC-0033). |
|
|
|
8 |
Reading, writing, or committing failed, or a required audit record could not be written. |
Check storage and the audit sink. |
|
|
8 |
The destination file exists. |
Choose another name, or allow overwriting. |
|
|
9 |
The |
|
|
|
70 |
An unexpected failure, redacted. |
Report it, with the operation identifier from the audit event. |
The command line adds exit code 2 with code USAGE_INVALID for invalid
arguments or configuration files.
Arguments of the wrong Python type raise TypeError, and values outside
their documented range raise ValueError, before any work starts: these are
programming errors, not runtime conditions.