pub enum CasError {
InvalidKey,
InvalidNonce,
InvalidSignature,
InvalidInput,
InvalidPemKey,
InvalidParameters,
EncryptionFailed,
DecryptionFailed,
SigningFailed,
KeyGenerationFailed,
PasswordHashingFailed,
CompressionFailed,
}Expand description
The unified error type returned by all fallible cas-lib operations.
Every cryptographic operation that can fail returns CasResult instead of
panicking. This is important for FFI consumers: a panic unwinding across the
FFI boundary is undefined behavior and typically aborts the host process. A
malformed key, a tampered ciphertext, or a failed authentication tag are all
recoverable conditions and are reported through this enum.
§ABI stability contract
The downstream FFI binding crates (cas-core-lib, cas-typescript-sdk)
surface each variant to their callers as the stable numeric code returned by
CasError::error_code. Those numbers are part of the ABI contract with
every consumer SDK, so this enum is append-only:
- Never remove, rename, or renumber an existing variant.
- Add new variants only at the end, and give them the next free code in
CasError::error_code.
The error_code_contract_is_stable test in this module pins the mapping so
an accidental reorder or removal fails CI here rather than silently breaking
a consumer’s error handling.
Variants§
InvalidKey
A provided key had an invalid length or could not be parsed.
InvalidNonce
A provided nonce/IV had an invalid length.
InvalidSignature
A provided signature had an invalid length or could not be parsed.
InvalidInput
Input bytes could not be decoded into the expected type.
InvalidPemKey
PEM/DER decoding or encoding of a key failed.
InvalidParameters
Invalid algorithm parameters were supplied (e.g. an RSA key size that is too small, or out-of-range password-hashing parameters).
EncryptionFailed
AEAD encryption failed.
DecryptionFailed
AEAD decryption failed or the authentication tag did not verify.
SigningFailed
A signing operation failed.
KeyGenerationFailed
Key generation failed.
PasswordHashingFailed
Password hashing or verification setup failed.
CompressionFailed
Compression or decompression failed.
Implementations§
Source§impl CasError
impl CasError
Sourcepub fn error_code(&self) -> i32
pub fn error_code(&self) -> i32
Maps this error to the stable numeric code surfaced through the FFI by
the downstream binding crates. 0 is reserved for success and is never
returned here.
These values are part of the ABI contract described on CasError; see
the type-level documentation before changing them.
Trait Implementations§
impl Eq for CasError
Source§impl Error for CasError
impl Error for CasError
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()