devela 0.28.0

A development substrate of coherence.
Documentation
// devela::data::codec::crypto::error
//
//! Defines [`CryptoError`].
//

use crate::{_impl_init, impl_trait};

#[doc = crate::_tags!(crypto error)]
/// An error from a cryptographic codec or primitive.
#[doc = crate::_doc_meta!{location("data/codec/crypto")}]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum CryptoError {
    /// The key length is invalid for the selected algorithm.
    InvalidKeyLength,

    /// The input length is invalid for the selected operation.
    InvalidLength,

    /// The input length exceeds the algorithm's supported range.
    LengthOverflow,

    /// A non-length operation parameter is invalid for the selected operation.
    InvalidParameter,

    /// Authentication, verification, or integrity checking failed.
    VerificationFailed,
}
impl CryptoError {
    /// Returns `true` for [`InvalidKeyLength`][CryptoError::InvalidKeyLength].
    pub const fn is_invalid_key_length(self) -> bool {
        matches!(self, Self::InvalidKeyLength)
    }
    /// Returns `true` for [`InvalidLength`][CryptoError::InvalidLength].
    pub const fn is_invalid_length(self) -> bool {
        matches!(self, Self::InvalidLength)
    }
    /// Returns `true` for [`InvalidParameter`][CryptoError::InvalidParameter].
    pub const fn is_invalid_parameter(self) -> bool {
        matches!(self, Self::InvalidParameter)
    }
    /// Returns `true` for [`LengthOverflow`][CryptoError::LengthOverflow].
    pub const fn is_length_overflow(self) -> bool {
        matches!(self, Self::LengthOverflow)
    }
    /// Returns `true` for [`VerificationFailed`][CryptoError::VerificationFailed].
    pub const fn is_verification_failed(self) -> bool {
        matches!(self, Self::VerificationFailed)
    }
}
_impl_init![Self::LengthOverflow => CryptoError];
impl_trait![fmt::Display+Error for CryptoError |self, f| match self {
    Self::InvalidKeyLength => f.write_str("invalid cryptographic key length"),
    Self::InvalidLength => f.write_str("invalid cryptographic input length"),
    Self::InvalidParameter => f.write_str("invalid cryptographic operation parameter"),
    Self::LengthOverflow => f.write_str("cryptographic input length overflow"),
    Self::VerificationFailed => f.write_str("cryptographic verification failed"),
}];