Skip to main content

Error

Enum Error 

Source
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.

Fields

§expected: usize
§actual: usize
§

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.

Fields

§expected: usize
§actual: usize
§

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).

Fields

§expected: usize
§actual: usize
§

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.

Fields

§max: usize
§actual: usize
§

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.

Fields

§expected: usize
§actual: usize
§

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.

Fields

§expected: usize
§actual: usize
§

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.

Fields

§max: usize
§actual: usize
§

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).

Fields

§expected: usize
§actual: usize
§

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).

Fields

§expected: usize
§actual: usize
§

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.

Fields

§algorithm: &'static str
§

InvalidSecurityLevel

Invalid security level

Fields

§level: u32
§supported: Vec<u32>
§

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.

Fields

§operation: String
§

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.

Fields

§operation: String
§

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.

Fields

§operation: String
§

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.

Fields

§operation: String
§

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.

Fields

§operation: String
§

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.

Fields

§operation: String
§

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.

Fields

§operation: String
§

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.

Fields

§operation: String
§details: String
§

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.

Fields

§feature: String
§

UnsupportedOperation

Unsupported operation

Fields

§operation: String
§

ProviderNotConfigured

No CryptoProvider configured on the context (distinct from stub NotImplemented)

Fields

§operation: String
§

InvalidState

Invalid state

Fields

§operation: String
§reason: String
§

PluginDependencyError

Plugin dependency error

Fields

§plugin: String
§dependency: String
§required_version: String
§available_version: Option<String>
§

PluginVersionIncompatible

Plugin version incompatibility

Fields

§plugin: String
§required_version: String
§available_version: String
§

InvalidKeyFormat

Invalid key format

§

InvalidKey

Invalid key with specific reason

Fields

§key_type: String
§reason: String
§

UnsupportedAlgorithm

Unsupported algorithm

Fields

§algorithm: String
§

AuthenticationFailed

Authentication failed

Fields

§operation: String
§

InvalidRandomnessSize

Invalid randomness size

Fields

§expected: usize
§actual: usize
§

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.

Fields

§min: usize
§max: usize
§requested: usize
§

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.

Fields

§capacity: usize
§requested: usize

Implementations§

Source§

impl Error

Source

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.

Source§

impl Error

WASM-friendly error handling

Source

pub fn message(&self) -> String

Get error message for WASM

Source

pub fn error_type(&self) -> String

Get error type name for WASM

Trait Implementations§

Source§

impl Clone for Error

Source§

fn clone(&self) -> Error

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Error

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Deserialize<'static> for Error

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'static>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Error

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for Error

Available on crate feature std only.
1.30.0 · Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<Error> for JsValue

Available on crate feature wasm only.

WASM error conversion

Source§

fn from(error: Error) -> Self

Converts to this type from the input type.
Source§

impl From<JsValue> for Error

Available on crate feature wasm only.
Source§

fn from(_js_value: JsValue) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Error

Source§

fn eq(&self, other: &Error) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Error

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for Error

Source§

impl StructuralPartialEq for Error

Auto Trait Implementations§

§

impl Freeze for Error

§

impl RefUnwindSafe for Error

§

impl Send for Error

§

impl Sync for Error

§

impl Unpin for Error

§

impl UnsafeUnpin for Error

§

impl UnwindSafe for Error

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more