#[derive(Debug, Clone, PartialEq, Eq)]
pub enum CryptoError {
InvalidKey,
InvalidNonce,
InvalidTag,
BufferTooSmall,
BadInput,
Internal(&'static str),
Kex,
Sign,
Rng,
Encoding,
UnsupportedAlgorithm,
}
impl core::fmt::Display for CryptoError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
CryptoError::InvalidKey => write!(f, "invalid key"),
CryptoError::InvalidNonce => write!(f, "invalid nonce"),
CryptoError::InvalidTag => write!(f, "invalid authentication tag"),
CryptoError::BufferTooSmall => write!(f, "output buffer too small"),
CryptoError::BadInput => write!(f, "bad input"),
CryptoError::Internal(msg) => write!(f, "internal error: {msg}"),
CryptoError::Kex => write!(f, "key exchange or encapsulation failure"),
CryptoError::Sign => write!(f, "signature generation or verification failure"),
CryptoError::Rng => write!(f, "random number generator failure"),
CryptoError::Encoding => write!(f, "encoding or decoding failure"),
CryptoError::UnsupportedAlgorithm => write!(f, "unsupported algorithm"),
}
}
}
impl core::error::Error for CryptoError {}
#[cfg(feature = "std")]
extern crate std;
#[cfg(feature = "std")]
impl From<CryptoError> for std::io::Error {
fn from(e: CryptoError) -> Self {
std::io::Error::other(alloc::format!("{e}"))
}
}