From cc18a545a87ca616f05114d174690e5cc9614669 Mon Sep 17 00:00:00 2001 From: Igor Tolmachev Date: Tue, 16 Jul 2024 17:24:33 +0900 Subject: Optimize encryption - Add archive for testing encryption of compressed files - Implement incorrect password check - Use custom crc32 function --- src/zip/driver.rs | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'src/zip/driver.rs') diff --git a/src/zip/driver.rs b/src/zip/driver.rs index 87f9c1a..62da39f 100644 --- a/src/zip/driver.rs +++ b/src/zip/driver.rs @@ -221,7 +221,7 @@ impl ArchiveRead for Zip { indexes.insert(name.clone(), i); files.push(ZipFileInfo::new( CompressionMethod::from_struct_id(cdr.compression_method)?, - EncryptionMethod::from_bit_flag(bit_flag), + EncryptionMethod::from_bif_flag(bit_flag, cdr.crc, cdr.dos_time), bit_flag, mtime, atime, @@ -258,11 +258,22 @@ impl ArchiveRead for Zip { self.files.get(index).ok_or(ZipError::FileNotFound.into()) } - fn get_file_reader<'d>( + #[inline] + fn get_file_reader<'d>(&'d mut self, index: usize) -> ZipResult> { + self.get_file_reader_with_optional_password(index, None) + } +} + +impl Zip { + pub fn comment(&self) -> &String { + &self.comment + } + + pub fn get_file_reader_with_optional_password<'d>( &'d mut self, index: usize, - password: Option<&str>, - ) -> ZipResult> { + password: Option<&[u8]>, + ) -> ZipResult<::FileReader<'d>> { Ok(ZipFileReader::new( &mut self.io, self.files.get(index).ok_or(ZipError::FileNotFound)?, @@ -271,12 +282,6 @@ impl ArchiveRead for Zip { } } -impl Zip { - pub fn comment(&self) -> &String { - &self.comment - } -} - impl ArchiveWrite for Zip { type FileWriter<'d> = ZipFileWriter<'d, Io> where Io: 'd; } -- cgit v1.2.3