aboutsummaryrefslogtreecommitdiff
path: root/src/zip/driver.rs
diff options
context:
space:
mode:
authorIgor Tolmachev <me@igorek.dev>2024-07-16 17:24:33 +0900
committerIgor Tolmachev <me@igorek.dev>2024-07-16 17:24:33 +0900
commitcc18a545a87ca616f05114d174690e5cc9614669 (patch)
tree51ec845115754bb1d8b41d82e5349db5343a40ec /src/zip/driver.rs
parenta83767f9fbd51df654901b52bdba7838f6a10bf9 (diff)
downloadarchivator-cc18a545a87ca616f05114d174690e5cc9614669.tar.gz
archivator-cc18a545a87ca616f05114d174690e5cc9614669.zip
Optimize encryption
- Add archive for testing encryption of compressed files - Implement incorrect password check - Use custom crc32 function
Diffstat (limited to 'src/zip/driver.rs')
-rw-r--r--src/zip/driver.rs25
1 files changed, 15 insertions, 10 deletions
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<Io: Read + Seek> ArchiveRead for Zip<Io> {
221 indexes.insert(name.clone(), i); 221 indexes.insert(name.clone(), i);
222 files.push(ZipFileInfo::new( 222 files.push(ZipFileInfo::new(
223 CompressionMethod::from_struct_id(cdr.compression_method)?, 223 CompressionMethod::from_struct_id(cdr.compression_method)?,
224 EncryptionMethod::from_bit_flag(bit_flag), 224 EncryptionMethod::from_bif_flag(bit_flag, cdr.crc, cdr.dos_time),
225 bit_flag, 225 bit_flag,
226 mtime, 226 mtime,
227 atime, 227 atime,
@@ -258,11 +258,22 @@ impl<Io: Read + Seek> ArchiveRead for Zip<Io> {
258 self.files.get(index).ok_or(ZipError::FileNotFound.into()) 258 self.files.get(index).ok_or(ZipError::FileNotFound.into())
259 } 259 }
260 260
261 fn get_file_reader<'d>( 261 #[inline]
262 fn get_file_reader<'d>(&'d mut self, index: usize) -> ZipResult<Self::FileReader<'d>> {
263 self.get_file_reader_with_optional_password(index, None)
264 }
265}
266
267impl<Io: Read + Seek> Zip<Io> {
268 pub fn comment(&self) -> &String {
269 &self.comment
270 }
271
272 pub fn get_file_reader_with_optional_password<'d>(
262 &'d mut self, 273 &'d mut self,
263 index: usize, 274 index: usize,
264 password: Option<&str>, 275 password: Option<&[u8]>,
265 ) -> ZipResult<Self::FileReader<'d>> { 276 ) -> ZipResult<<Self as ArchiveRead>::FileReader<'d>> {
266 Ok(ZipFileReader::new( 277 Ok(ZipFileReader::new(
267 &mut self.io, 278 &mut self.io,
268 self.files.get(index).ok_or(ZipError::FileNotFound)?, 279 self.files.get(index).ok_or(ZipError::FileNotFound)?,
@@ -271,12 +282,6 @@ impl<Io: Read + Seek> ArchiveRead for Zip<Io> {
271 } 282 }
272} 283}
273 284
274impl<Io: Read + Seek> Zip<Io> {
275 pub fn comment(&self) -> &String {
276 &self.comment
277 }
278}
279
280impl<Io: Read + Write + Seek> ArchiveWrite for Zip<Io> { 285impl<Io: Read + Write + Seek> ArchiveWrite for Zip<Io> {
281 type FileWriter<'d> = ZipFileWriter<'d, Io> where Io: 'd; 286 type FileWriter<'d> = ZipFileWriter<'d, Io> where Io: 'd;
282} 287}