Skip to content

Commit

Permalink
Make make_crypto_reader take ZipFileData directly
Browse files Browse the repository at this point in the history
  • Loading branch information
a1phyr committed Jul 16, 2024
1 parent deb71ba commit e9b1312
Showing 1 changed file with 8 additions and 31 deletions.
39 changes: 8 additions & 31 deletions src/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,18 +294,14 @@ fn find_data_start(

#[allow(clippy::too_many_arguments)]
pub(crate) fn make_crypto_reader<'a>(
compression_method: CompressionMethod,
crc32: u32,
mut last_modified_time: Option<DateTime>,
using_data_descriptor: bool,
data: &ZipFileData,
reader: io::Take<&'a mut dyn Read>,
password: Option<&[u8]>,
aes_info: Option<(AesMode, AesVendorVersion, CompressionMethod)>,
#[cfg(feature = "aes-crypto")] compressed_size: u64,
) -> ZipResult<CryptoReader<'a>> {
#[allow(deprecated)]
{
if let CompressionMethod::Unsupported(_) = compression_method {
if let CompressionMethod::Unsupported(_) = data.compression_method {
return unsupported_zip_error("Compression method not supported");
}
}
Expand All @@ -319,17 +315,18 @@ pub(crate) fn make_crypto_reader<'a>(
}
#[cfg(feature = "aes-crypto")]
(Some(password), Some((aes_mode, vendor_version, _))) => CryptoReader::Aes {
reader: AesReader::new(reader, aes_mode, compressed_size).validate(password)?,
reader: AesReader::new(reader, aes_mode, data.compressed_size).validate(password)?,
vendor_version,
},
(Some(password), None) => {
if !using_data_descriptor {
let mut last_modified_time = data.last_modified_time;
if !data.using_data_descriptor {
last_modified_time = None;
}
let validator = if let Some(last_modified_time) = last_modified_time {
ZipCryptoValidator::InfoZipMsdosTime(last_modified_time.timepart())
} else {
ZipCryptoValidator::PkzipCrc32(crc32)
ZipCryptoValidator::PkzipCrc32(data.crc32)
};
CryptoReader::ZipCrypto(ZipCryptoReader::new(reader, password).validate(validator)?)
}
Expand Down Expand Up @@ -1085,17 +1082,7 @@ impl<R: Read + Seek> ZipArchive<R> {
}
let limit_reader = find_content(data, &mut self.reader)?;

let crypto_reader = make_crypto_reader(
data.compression_method,
data.crc32,
data.last_modified_time,
data.using_data_descriptor,
limit_reader,
password,
data.aes_mode,
#[cfg(feature = "aes-crypto")]
data.compressed_size,
)?;
let crypto_reader = make_crypto_reader(data, limit_reader, password, data.aes_mode)?;

Ok(ZipFile {
data: Cow::Borrowed(data),
Expand Down Expand Up @@ -1616,17 +1603,7 @@ pub fn read_zipfile_from_stream<'a, R: Read>(reader: &'a mut R) -> ZipResult<Opt

let result_crc32 = result.crc32;
let result_compression_method = result.compression_method;
let crypto_reader = make_crypto_reader(
result_compression_method,
result_crc32,
result.last_modified_time,
result.using_data_descriptor,
limit_reader,
None,
None,
#[cfg(feature = "aes-crypto")]
result.compressed_size,
)?;
let crypto_reader = make_crypto_reader(&result, limit_reader, None, None)?;

Ok(Some(ZipFile {
data: Cow::Owned(result),
Expand Down

0 comments on commit e9b1312

Please sign in to comment.