pub struct Decryptor<R> { /* private fields */ }Expand description
A Read adapter that decrypts a ZipCrypto entry on the fly.
On construction it consumes the 12-byte encryption header; reads then yield the decrypted (but still compressed) body, so wrap it in a decompressor to recover the original data.
ZipCrypto’s single check byte is weak verification, so still validate the
output against the entry’s CRC32 (e.g. via ZipSliceEntry::verifying_reader).
§Examples
let data = std::fs::read("assets/zipcrypto.zip")?;
let archive = ZipArchive::from_slice(&data)?;
let entry = archive.entries().next().unwrap()?;
let zip_entry = archive.get_entry(entry.wayfinder())?;
let decryptor = Decryptor::new(zip_entry.data(), b"rawzipiscool")?;
// Optionally, for a cheap up-front password check, use `check_byte`. Omitted from
// the example for brevity.
let inflater = flate2::read::DeflateDecoder::new(decryptor);
// The verifying reader checks the decrypted data against the entry's CRC32.
let mut output = Vec::new();
zip_entry.verifying_reader(inflater).read_to_end(&mut output)?;
assert_eq!(output, b"aaaaaaaaaaaaaaaa\n");Implementations§
Source§impl<R: Read> Decryptor<R>
impl<R: Read> Decryptor<R>
Sourcepub fn new(reader: R, password: &[u8]) -> Result<Self>
pub fn new(reader: R, password: &[u8]) -> Result<Self>
Wraps a reader positioned at the start of an entry’s encrypted data, reading and decrypting the encryption header.
Check check_byte afterwards for a cheap
password sanity test.
Sourcepub fn check_byte(&self) -> u8
pub fn check_byte(&self) -> u8
The final byte of the decrypted header, a 1-in-256 password check.
Equals the high byte of the entry’s CRC32, or of its DOS mod time when the entry carries a data descriptor
Sourcepub fn into_inner(self) -> R
pub fn into_inner(self) -> R
Consumes the reader, returning the wrapped reader.
Trait Implementations§
Source§impl<R: Read> Read for Decryptor<R>
impl<R: Read> Read for Decryptor<R>
Source§fn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
1.36.0 · Source§fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
read, except that it reads into a slice of buffers. Read moreSource§fn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector)1.0.0 · Source§fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
buf. Read more1.0.0 · Source§fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
buf. Read more1.6.0 · Source§fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
buf. Read moreSource§fn read_buf(&mut self, buf: BorrowedCursor<'_, u8>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_, u8>) -> Result<(), Error>
read_buf)Source§fn read_buf_exact(
&mut self,
cursor: BorrowedCursor<'_, u8>,
) -> Result<(), Error>
fn read_buf_exact( &mut self, cursor: BorrowedCursor<'_, u8>, ) -> Result<(), Error>
read_buf)cursor. Read more1.0.0 · Source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Read. Read more1.0.0 · Source§fn chain<R>(self, next: R) -> Chain<Self, R> ⓘ
fn chain<R>(self, next: R) -> Chain<Self, R> ⓘ
1.0.0 · Source§fn take(self, limit: u64) -> Take<Self> ⓘwhere
Self: Sized,
fn take(self, limit: u64) -> Take<Self> ⓘwhere
Self: Sized,
limit bytes from it. Read moreSource§fn read_array<const N: usize>(&mut self) -> Result<[u8; N], Error>where
Self: Sized,
fn read_array<const N: usize>(&mut self) -> Result<[u8; N], Error>where
Self: Sized,
read_array)