use crate::{_impl_init, impl_trait};
#[doc = crate::_tags!(crypto error)]
#[doc = crate::_doc_meta!{location("data/codec/crypto")}]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum CryptoError {
InvalidKeyLength,
InvalidLength,
LengthOverflow,
InvalidParameter,
VerificationFailed,
}
impl CryptoError {
pub const fn is_invalid_key_length(self) -> bool {
matches!(self, Self::InvalidKeyLength)
}
pub const fn is_invalid_length(self) -> bool {
matches!(self, Self::InvalidLength)
}
pub const fn is_invalid_parameter(self) -> bool {
matches!(self, Self::InvalidParameter)
}
pub const fn is_length_overflow(self) -> bool {
matches!(self, Self::LengthOverflow)
}
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"),
}];