use std::fmt;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum CoreError {
InvalidKeyLength { expected: usize, got: usize },
InvalidMultikey(String),
UnknownMulticodec(String),
InvalidDid(String),
InvalidSignatureLength { expected: usize, got: usize },
Crypto(String),
Json(String),
Threshold(String),
}
impl fmt::Display for CoreError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
CoreError::InvalidKeyLength { expected, got } => {
write!(
f,
"invalid key length: expected {expected} bytes, got {got}"
)
}
CoreError::InvalidMultikey(m) => write!(f, "invalid multikey: {m}"),
CoreError::UnknownMulticodec(m) => write!(f, "unknown multicodec prefix: {m}"),
CoreError::InvalidDid(m) => write!(f, "invalid did: {m}"),
CoreError::InvalidSignatureLength { expected, got } => {
write!(
f,
"invalid signature length: expected {expected} bytes, got {got}"
)
}
CoreError::Crypto(m) => write!(f, "crypto error: {m}"),
CoreError::Json(m) => write!(f, "json error: {m}"),
CoreError::Threshold(m) => write!(f, "threshold signing error: {m}"),
}
}
}
impl std::error::Error for CoreError {}
pub type Result<T> = std::result::Result<T, CoreError>;