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#[derive(Error, Debug)]
8pub enum DecryptionError {
9    #[error("generic decryption error: {0}")]
10    Generic(String)
11}
12
13#[derive(Error, Debug)]
14pub enum DecryptorCreationError {
15    #[error("generic decryptor creation error: {0}")]
16    Generic(String),
17
18    #[error("incorrect password")]
19    IncorrectPassword,
20
21    #[error("data is not encrypted")]
22    NotEncrypted
23}
24
25pub trait Decryptor: std::fmt::Debug + Send + Sync {
26    /// Tries to decrypt data
27    ///
28    /// The return values are the amount of input bytes consumed,
29    /// and the result of this decryption operation
30    fn update(&mut self, data: &[u8]) -> Result<(usize, &[u8]), DecryptionError>;
31}