Skip to main content

cpt/
error.rs

1use std::fmt::{self};
2
3use binrw::io;
4
5#[derive(Debug, Clone, Copy)]
6pub enum Feature {
7    Encryption,
8    LzhCompression,
9    RleCompression,
10}
11
12impl std::fmt::Display for Feature {
13    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
14        match self {
15            Feature::Encryption => write!(f, "Encryption"),
16            Feature::LzhCompression => write!(f, "LzHuffman compression"),
17            Feature::RleCompression => write!(f, "RLE compression"),
18        }
19    }
20}
21
22#[derive(Debug, thiserror::Error)]
23pub enum Error {
24    #[error(transparent)]
25    BinRw(#[from] binrw::Error),
26    #[error(transparent)]
27    Io(#[from] std::io::Error),
28    #[error("Archive uses an unsupported feature ({0})")]
29    UnsupportedFeature(Feature),
30    #[error("The file is not a CPT archive")]
31    InvalidFile,
32}
33
34#[derive(thiserror::Error, Debug)]
35pub enum VerificationError {
36    #[error("One ore more checksums are invalid")]
37    InvalidChecksum,
38
39    #[error(transparent)]
40    Error(#[from] Error),
41}
42
43impl From<io::Error> for VerificationError {
44    fn from(value: io::Error) -> Self {
45        VerificationError::Error(value.into())
46    }
47}