use alloc::string::String;
use thiserror::Error;
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum VerifierError {
#[error("X-H33-Substrate header must be 64 hex characters (32 bytes), got {actual}")]
InvalidSubstrateHeaderLength {
actual: usize,
},
#[error("X-H33-Substrate header is not valid hex: {0}")]
InvalidSubstrateHeaderHex(String),
#[error("X-H33-Receipt header must be 84 hex characters (42 bytes), got {actual}")]
InvalidReceiptHeaderLength {
actual: usize,
},
#[error("X-H33-Receipt header is not valid hex: {0}")]
InvalidReceiptHeaderHex(String),
#[error("CompactReceipt version byte is 0x{actual:02X}, expected 0x{expected:02X}")]
UnsupportedReceiptVersion {
actual: u8,
expected: u8,
},
#[error("CompactReceipt must decode to exactly {expected} bytes, got {actual}")]
InvalidReceiptSize {
actual: usize,
expected: usize,
},
#[error(
"CompactReceipt algorithm flags 0x{flags:02X} contain unrecognized bits; \
verifier only knows Dilithium (0x01), FALCON (0x02), SPHINCS+ (0x04)"
)]
UnknownAlgorithmBits {
flags: u8,
},
#[error("public keys JSON parse failed: {0}")]
PublicKeysParse(String),
#[error("public keys contained invalid base64 for field `{field}`: {detail}")]
PublicKeysBase64 {
field: &'static str,
detail: String,
},
#[error("unknown algorithm identifier in X-H33-Algorithms: `{0}`")]
UnknownAlgorithm(String),
}
#[cfg(feature = "std")]
impl From<VerifierError> for std::io::Error {
fn from(e: VerifierError) -> Self {
Self::new(std::io::ErrorKind::InvalidData, e.to_string())
}
}