use super::code::IndexedSigCode;
#[cfg(feature = "alloc")]
#[allow(
unused_imports,
reason = "alloc prelude items; subset used per cfg/feature combination"
)]
use alloc::string::String;
use thiserror::Error as ThisError;
#[derive(Debug, ThisError, PartialEq, Eq)]
pub enum IndexerParseError {
#[error("empty CESR stream")]
EmptyStream,
#[error("stream too short: need {need} chars, got {got}")]
StreamTooShort {
need: usize,
got: usize,
},
#[error("unknown indexed sig code: '{0}'")]
UnknownCode(String),
#[error("invalid base64 in indexed sig stream")]
InvalidBase64,
#[error("non-canonical encoding: leading zeros in indexed sig")]
NonCanonical,
#[error("ondex must be 0 for current-only code, got {0}")]
OndexNotZeroForCurrentOnly(u32),
}
#[derive(Debug, ThisError, PartialEq, Eq)]
pub enum IndexerValidationError {
#[error("index {index} exceeds max {max} for code {code:?}")]
IndexTooLarge {
code: IndexedSigCode,
index: u32,
max: u32,
},
#[error("ondex {ondex} exceeds max {max} for code {code:?}")]
OndexTooLarge {
code: IndexedSigCode,
ondex: u32,
max: u32,
},
#[error("ondex not allowed for current-only code {0:?}")]
OndexOnCurrentOnly(IndexedSigCode),
#[error("ondex {ondex} must equal index {index} for code {code:?} (os=0)")]
OndexMustEqualIndex {
code: IndexedSigCode,
index: u32,
ondex: u32,
},
#[error("unexpected raw size for {code:?}: expected {expected}, got {got}")]
UnexpectedRawSize {
code: IndexedSigCode,
expected: usize,
got: usize,
},
}
impl From<super::code::CodeError> for IndexerParseError {
fn from(e: super::code::CodeError) -> Self {
match e {
super::code::CodeError::UnknownCode(s) => Self::UnknownCode(s),
}
}
}
impl From<crate::b64::error::Error> for IndexerParseError {
fn from(e: crate::b64::error::Error) -> Self {
match e {
crate::b64::error::Error::InvalidBase64Char(_)
| crate::b64::error::Error::InvalidBase64Value(_)
| crate::b64::error::Error::IntegerOverflow => Self::InvalidBase64,
crate::b64::error::Error::ShortBinaryStream => Self::StreamTooShort { need: 0, got: 0 },
}
}
}