pub enum Error {
Show 33 variants
InvalidKeySize {
expected: usize,
actual: usize,
},
InvalidSignatureSize {
expected: usize,
actual: usize,
},
InvalidNonceSize {
expected: usize,
actual: usize,
},
InvalidMessageSize {
max: usize,
actual: usize,
},
InvalidCiphertextSize {
expected: usize,
actual: usize,
},
InvalidPlaintextSize {
expected: usize,
actual: usize,
},
InvalidAssociatedDataSize {
max: usize,
actual: usize,
},
InvalidTagSize {
expected: usize,
actual: usize,
},
InvalidHashSize {
expected: usize,
actual: usize,
},
InvalidAlgorithm {
algorithm: &'static str,
},
InvalidSecurityLevel {
level: u32,
supported: Vec<u32>,
},
VerificationFailed {
operation: String,
},
EncryptionFailed {
operation: String,
},
DecryptionFailed {
operation: String,
},
KeyGenerationFailed {
operation: String,
},
RandomGenerationFailed {
operation: String,
},
SigningFailed {
operation: String,
},
MemoryAllocationFailed {
operation: String,
},
InternalError {
operation: String,
details: String,
},
NotImplemented {
feature: String,
},
UnsupportedOperation {
operation: String,
},
ProviderNotConfigured {
operation: String,
},
InvalidState {
operation: String,
reason: String,
},
PluginDependencyError {
plugin: String,
dependency: String,
required_version: String,
available_version: Option<String>,
},
PluginVersionIncompatible {
plugin: String,
required_version: String,
available_version: String,
},
InvalidKeyFormat,
InvalidKey {
key_type: String,
reason: String,
},
UnsupportedAlgorithm {
algorithm: String,
},
AuthenticationFailed {
operation: String,
},
InvalidRandomnessSize {
expected: usize,
actual: usize,
},
RandomBytesLengthInvalid {
min: usize,
max: usize,
requested: usize,
},
HexDecode(HexDecodeError),
BufferTooSmall {
capacity: usize,
requested: usize,
},
}Expand description
The error type for lib-Q operations
This enum represents all possible errors that can occur during cryptographic operations across all libQ libraries. Each variant includes context about when the error occurs.
Variants§
InvalidKeySize
Invalid key size
When it occurs: A key (public or secret) has an incorrect size for the algorithm. Cause: The key data provided doesn’t match the expected size for the algorithm variant. Resolution: Ensure the key size matches the algorithm’s requirements. Check algorithm documentation for expected key sizes.
InvalidSignatureSize
Invalid signature size
When it occurs: A signature has an incorrect size for the algorithm. Cause: The signature data doesn’t match the expected size for verification. Resolution: Ensure the signature was generated for the same algorithm variant and hasn’t been corrupted.
InvalidNonceSize
Invalid nonce size
When it occurs: A nonce has an incorrect size for the operation. Cause: The nonce doesn’t meet the size requirements for the cryptographic operation. Resolution: Ensure the nonce size matches the algorithm’s requirements (typically 12-16 bytes for AEAD).
InvalidMessageSize
Invalid message size
When it occurs: A caller-supplied message or payload exceeds a configured policy limit
(for example AEAD or hash absorb bounds from crate::security::SecurityValidator).
Cause: The input is too large for the operation under current security constants.
Resolution: Split the message into smaller chunks or use a different approach that supports larger messages.
For fixed internal or stack buffers, use Error::BufferTooSmall instead.
InvalidCiphertextSize
Invalid ciphertext size
When it occurs: A ciphertext has an incorrect size for decryption. Cause: The ciphertext data doesn’t match the expected size for the algorithm. Resolution: Ensure the ciphertext was generated for the same algorithm and hasn’t been corrupted.
InvalidPlaintextSize
Invalid plaintext size
When it occurs: A plaintext has an incorrect size for the operation. Cause: The plaintext doesn’t meet the size requirements for encryption. Resolution: Verify the plaintext size matches the algorithm’s requirements.
InvalidAssociatedDataSize
Invalid associated data size
When it occurs: Associated data exceeds the maximum allowed size. Cause: The associated data is too large for the AEAD operation. Resolution: Reduce the associated data size or use a different approach.
InvalidTagSize
Invalid tag size
When it occurs: An authentication tag has an incorrect size. Cause: The tag doesn’t match the expected size for the AEAD algorithm. Resolution: Ensure the tag size matches the algorithm’s requirements (typically 16 bytes).
InvalidHashSize
Invalid hash size
When it occurs: A hash output has an incorrect size. Cause: The hash size doesn’t match the expected output length for the hash function. Resolution: Ensure the hash size matches the algorithm’s output length (e.g., SHA-256 = 32 bytes).
InvalidAlgorithm
Invalid algorithm
When it occurs: An unsupported or invalid algorithm is specified. Cause: The algorithm identifier doesn’t match any supported algorithm, or the algorithm isn’t available in the current configuration. Resolution: Check that the algorithm is supported and that required features are enabled.
InvalidSecurityLevel
Invalid security level
VerificationFailed
Verification failed
When it occurs: Signature or message authentication verification fails. Cause: The signature is invalid, the message was tampered with, or the verification key is incorrect. Resolution: Verify the signature, message, and key are correct and correspond to each other.
EncryptionFailed
Encryption failed
When it occurs: Encryption or encapsulation fails to produce a valid ciphertext. Cause: Random number generation may have failed, or internal computation encountered an error. Resolution: Ensure a secure random number generator is available and functioning correctly.
DecryptionFailed
Decryption failed
When it occurs: Decryption or decapsulation fails to recover the plaintext or shared secret. Cause: The ciphertext may be corrupted, the key may be incorrect, or authentication failed. Resolution: Verify the ciphertext and key are valid and correspond to each other.
KeyGenerationFailed
Key generation failed
When it occurs: Key pair generation fails. Cause: Random number generation may have failed, or internal computation encountered an error. Resolution: Ensure a secure random number generator is available and functioning correctly.
RandomGenerationFailed
Random number generation failed
When it occurs: The random number generator fails to produce random bytes. Cause: The underlying RNG implementation encountered an error or is unavailable. Resolution: Check RNG initialization and ensure a secure random source is available.
SigningFailed
Signing failed
When it occurs: Digital signature generation fails. Cause: Random number generation may have failed, or internal computation encountered an error. Resolution: Ensure a secure random number generator is available and functioning correctly.
MemoryAllocationFailed
Memory allocation failed
When it occurs: Dynamic memory allocation fails during an operation. Cause: Insufficient memory is available, or allocation is not supported in the current environment. Resolution: Ensure sufficient memory is available, or use a no_std-compatible configuration.
InternalError
Internal error
When it occurs: An unexpected internal error occurs during cryptographic operations. Cause: This typically indicates a bug in the implementation or corrupted internal state. Resolution: Report this error as it may indicate a software bug. Check inputs and system state.
NotImplemented
Not implemented
When it occurs: A requested feature or operation is not yet implemented. Cause: The operation is not available in the current implementation. Resolution: Check if an alternative approach is available, or wait for the feature to be implemented.
UnsupportedOperation
Unsupported operation
ProviderNotConfigured
No CryptoProvider configured on the context (distinct from stub NotImplemented)
InvalidState
Invalid state
PluginDependencyError
Plugin dependency error
PluginVersionIncompatible
Plugin version incompatibility
InvalidKeyFormat
Invalid key format
InvalidKey
Invalid key with specific reason
UnsupportedAlgorithm
Unsupported algorithm
AuthenticationFailed
Authentication failed
InvalidRandomnessSize
Invalid randomness size
RandomBytesLengthInvalid
Requested output length for crate::api::Utils::random_bytes is outside the supported range.
When it occurs: length is zero or exceeds the platform-specific maximum for this helper.
Resolution: Use a length in the inclusive range given by min and max.
HexDecode(HexDecodeError)
Hexadecimal decoding failed (crate::api::Utils::hex_to_bytes).
BufferTooSmall
A fixed-capacity buffer (stack or internal) cannot satisfy the requested byte length.
When it occurs: An implementation uses a bounded temporary buffer and the requested
length exceeds that capacity. This is distinct from Error::InvalidMessageSize, which
reflects configured cryptographic policy limits on caller-supplied payloads.
Implementations§
Source§impl Error
impl Error
Sourcepub const fn aead_ciphertext_shorter_than_tag(
tag_len: usize,
actual_len: usize,
) -> Self
pub const fn aead_ciphertext_shorter_than_tag( tag_len: usize, actual_len: usize, ) -> Self
AEAD ciphertext is shorter than the minimum length required to hold an authentication tag.
This is an operational input error (Layer A / pre-decrypt validation). It must not be
used for tag mismatch after the decrypt/verify schedule; that path uses
Error::VerificationFailed or DecryptSemanticOutcome::AuthenticationFailed.
Trait Implementations§
Source§impl Deserialize<'static> for Error
impl Deserialize<'static> for Error
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'static>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'static>,
Source§impl Error for Error
Available on crate feature std only.
impl Error for Error
std only.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()