use std::fmt::{self};
use binrw::io;
#[derive(Debug, Clone, Copy)]
pub enum Feature {
Encryption,
LzhCompression,
RleCompression,
}
impl std::fmt::Display for Feature {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Feature::Encryption => write!(f, "Encryption"),
Feature::LzhCompression => write!(f, "LzHuffman compression"),
Feature::RleCompression => write!(f, "RLE compression"),
}
}
}
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error(transparent)]
BinRw(#[from] binrw::Error),
#[error(transparent)]
Io(#[from] std::io::Error),
#[error("Archive uses an unsupported feature ({0})")]
UnsupportedFeature(Feature),
#[error("The file is not a CPT archive")]
InvalidFile,
}
#[derive(thiserror::Error, Debug)]
pub enum VerificationError {
#[error("One ore more checksums are invalid")]
InvalidChecksum,
#[error(transparent)]
Error(#[from] Error),
}
impl From<io::Error> for VerificationError {
fn from(value: io::Error) -> Self {
VerificationError::Error(value.into())
}
}