Skip to main content

stream_unpack/decrypt/
mod.rs

1use thiserror::Error;
2
3/// Provides a [Decryptor] for the ZipCrypto (PKWARE encryption) algorithm, used in old ZIP files.
4#[cfg(feature = "zipcrypto")]
5pub mod zipcrypto;
6
7/// Provides a [Decryptor] for the AE-x algorithm, used in ZIP files.
8#[cfg(feature = "ae-x")]
9pub mod aex;
10
11#[derive(Error, Debug)]
12pub enum DecryptionError {
13    #[error("generic decryption error: {0}")]
14    Generic(String)
15}
16
17#[derive(Error, Debug)]
18pub enum DecryptorCreationError {
19    #[error("generic decryptor creation error: {0}")]
20    Generic(String),
21
22    #[error("missing feature flag for encryption method: {0}")]
23    NoFeature(String),
24
25    #[error("incorrect password")]
26    IncorrectPassword,
27
28    #[error("data is not encrypted")]
29    NotEncrypted
30}
31
32pub trait Decryptor: std::fmt::Debug + Send + Sync {
33    /// Tries to decrypt data
34    ///
35    /// The return values are the amount of input bytes consumed,
36    /// and the result of this decryption operation
37    fn update(&mut self, data: &[u8]) -> Result<(usize, &[u8]), DecryptionError>;
38}