pkcrack 0.1.0

A Rust implementation of pkcrack - Known-plaintext attack against PkZip encryption
Documentation
//! Error handling for pkcrack

use thiserror::Error;

pub type Result<T> = std::result::Result<T, PkCrackError>;

#[derive(Error, Debug)]
pub enum PkCrackError {
    #[error("I/O error: {0}")]
    Io(#[from] std::io::Error),

    #[error("Configuration error: {0}")]
    Config(String),

    #[error("File not found: {0}")]
    FileNotFound(String),

    #[error("Invalid file format: {0}")]
    InvalidFormat(String),

    #[error("Insufficient memory")]
    InsufficientMemory,

    #[error("Invalid ZIP archive: {0}")]
    InvalidZip(String),

    #[error("File not found in ZIP: {0}")]
    FileNotFoundInZip(String),

    #[error("Invalid parameters: {0}")]
    InvalidParameters(String),

    #[error("Plaintext too short (minimum 13 bytes required, got {0})")]
    PlaintextTooShort(usize),

    #[error("Plaintext longer than ciphertext")]
    PlaintextTooLong,

    #[error("No solution found - wrong plaintext?")]
    NoSolutionFound,

    #[error("Attack failed at stage {stage}: {reason}")]
    AttackFailed { stage: u8, reason: String },

    #[error("CRC error: {0}")]
    Crc(String),

    #[error("Cryptographic error: {0}")]
    Crypto(String),

    #[error("Unexpected error: {0}")]
    Unexpected(String),
}

impl PkCrackError {
    pub fn config(msg: impl Into<String>) -> Self {
        Self::Config(msg.into())
    }

    pub fn invalid_format(msg: impl Into<String>) -> Self {
        Self::InvalidFormat(msg.into())
    }

    pub fn attack_failed(stage: u8, reason: impl Into<String>) -> Self {
        Self::AttackFailed {
            stage,
            reason: reason.into(),
        }
    }

    pub fn crypto(msg: impl Into<String>) -> Self {
        Self::Crypto(msg.into())
    }

    pub fn unexpected(msg: impl Into<String>) -> Self {
        Self::Unexpected(msg.into())
    }
}