#[cfg(not(feature = "thiserror"))]
use core::fmt;
pub type Result<T> = core::result::Result<T, CryptoError>;
pub type CryptoResult<T> = core::result::Result<T, CryptoError>;
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "thiserror", derive(thiserror::Error))]
pub enum CryptoError {
#[cfg_attr(feature = "thiserror", error("Invalid VRF proof"))]
InvalidProof,
#[cfg_attr(feature = "thiserror", error("Invalid public key"))]
InvalidPublicKey,
#[cfg_attr(feature = "thiserror", error("Invalid secret key"))]
InvalidSecretKey,
#[cfg_attr(feature = "thiserror", error("Invalid point encoding"))]
InvalidPoint,
#[cfg_attr(feature = "thiserror", error("Invalid scalar"))]
InvalidScalar,
#[cfg_attr(feature = "thiserror", error("VRF verification failed"))]
VerificationFailed,
#[cfg_attr(feature = "thiserror", error("Invalid input"))]
InvalidInput,
#[cfg_attr(feature = "thiserror", error("Key generation failed"))]
KeyGenerationFailed,
#[cfg_attr(feature = "thiserror", error("KES evolution error"))]
KesEvolutionError,
#[cfg_attr(feature = "thiserror", error("KES period out of range"))]
KesPeriodError,
#[cfg_attr(feature = "thiserror", error("Invalid key length"))]
InvalidKeyLength,
#[cfg_attr(feature = "thiserror", error("Invalid signature"))]
InvalidSignature,
#[cfg_attr(feature = "thiserror", error("Key has expired"))]
KeyExpired,
#[cfg_attr(feature = "thiserror", error("Invalid period"))]
InvalidPeriod,
#[cfg_attr(feature = "thiserror", error("Serialization error"))]
SerializationError,
#[cfg_attr(feature = "thiserror", error("Deserialization error"))]
DeserializationError,
#[cfg_attr(feature = "thiserror", error("Cryptographic operation failed"))]
CryptoFailure,
#[cfg(feature = "kes")]
#[cfg_attr(feature = "thiserror", error("KES error: {0}"))]
KesError(crate::kes::KesError),
#[cfg_attr(feature = "thiserror", error("{0}"))]
Other(&'static str),
}
#[cfg(not(feature = "thiserror"))]
impl fmt::Display for CryptoError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
CryptoError::InvalidProof => write!(f, "Invalid VRF proof"),
CryptoError::InvalidPublicKey => write!(f, "Invalid public key"),
CryptoError::InvalidSecretKey => write!(f, "Invalid secret key"),
CryptoError::InvalidPoint => write!(f, "Invalid point encoding"),
CryptoError::InvalidScalar => write!(f, "Invalid scalar"),
CryptoError::VerificationFailed => write!(f, "VRF verification failed"),
CryptoError::InvalidInput => write!(f, "Invalid input"),
CryptoError::KeyGenerationFailed => write!(f, "Key generation failed"),
CryptoError::KesEvolutionError => write!(f, "KES evolution error"),
CryptoError::KesPeriodError => write!(f, "KES period out of range"),
CryptoError::InvalidKeyLength => write!(f, "Invalid key length"),
CryptoError::InvalidSignature => write!(f, "Invalid signature"),
CryptoError::KeyExpired => write!(f, "Key has expired"),
CryptoError::InvalidPeriod => write!(f, "Invalid period"),
CryptoError::SerializationError => write!(f, "Serialization error"),
CryptoError::DeserializationError => write!(f, "Deserialization error"),
CryptoError::CryptoFailure => write!(f, "Cryptographic operation failed"),
#[cfg(feature = "kes")]
CryptoError::KesError(e) => write!(f, "KES error: {}", e),
CryptoError::Other(msg) => write!(f, "{}", msg),
}
}
}
#[cfg(all(not(feature = "thiserror"), feature = "std"))]
impl std::error::Error for CryptoError {}
#[cfg(all(not(feature = "thiserror"), not(feature = "std")))]
impl core::error::Error for CryptoError {}