use std::fmt;
#[derive(Debug, Clone, PartialEq)]
pub enum PoCXHashError {
AllocationError(String),
BufferSizeError(String),
InvalidInput(String),
HexDecodeError(String),
LayoutError(String),
QualityMismatch {
expected: u64,
actual: u64,
proof_index: usize,
},
}
impl fmt::Display for PoCXHashError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
PoCXHashError::AllocationError(msg) => write!(f, "Memory allocation failed: {}", msg),
PoCXHashError::BufferSizeError(msg) => write!(f, "Buffer size error: {}", msg),
PoCXHashError::InvalidInput(msg) => write!(f, "Invalid input: {}", msg),
PoCXHashError::HexDecodeError(msg) => write!(f, "Hex decode error: {}", msg),
PoCXHashError::LayoutError(msg) => write!(f, "Layout error: {}", msg),
PoCXHashError::QualityMismatch {
expected,
actual,
proof_index,
} => write!(
f,
"Quality mismatch at proof {}: expected {}, got {}",
proof_index, expected, actual
),
}
}
}
impl std::error::Error for PoCXHashError {}
impl From<hex::FromHexError> for PoCXHashError {
fn from(err: hex::FromHexError) -> Self {
PoCXHashError::HexDecodeError(err.to_string())
}
}
pub type Result<T> = std::result::Result<T, PoCXHashError>;