Skip to content
This repository has been archived by the owner on Jun 2, 2024. It is now read-only.

Commit

Permalink
chore: fix wrong formatting (cargo fmt / rustfmt)
Browse files Browse the repository at this point in the history
  • Loading branch information
striezel committed Aug 29, 2023
1 parent b3b840c commit 682a9ba
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/unstable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub mod write {
/// Unstable methods for [`FileOptions`].
pub trait FileOptionsExt {
/// Write the file with the given password using the deprecated ZipCrypto algorithm.
///
///
/// This is not recommended for new archives, as ZipCrypto is not secure.
fn with_deprecated_encryption(self, password: &[u8]) -> Self;
}
Expand All @@ -17,4 +17,4 @@ pub mod write {
self.with_deprecated_encryption(password)
}
}
}
}
11 changes: 8 additions & 3 deletions src/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,11 @@ impl<W: Write + io::Seek> ZipWriter<W> {
self.files.push(file);
}
if let Some(keys) = options.encrypt_with {
let mut zipwriter = crate::zipcrypto::ZipCryptoWriter { writer: core::mem::replace(&mut self.inner, GenericZipWriter::Closed).unwrap(), buffer: vec![], keys };
let mut zipwriter = crate::zipcrypto::ZipCryptoWriter {
writer: core::mem::replace(&mut self.inner, GenericZipWriter::Closed).unwrap(),
buffer: vec![],
keys,
};
let crypto_header = [0u8; 12];

zipwriter.write_all(&crypto_header)?;
Expand All @@ -428,10 +432,11 @@ impl<W: Write + io::Seek> ZipWriter<W> {
match core::mem::replace(&mut self.inner, GenericZipWriter::Closed) {
GenericZipWriter::Storer(MaybeEncrypted::Encrypted(writer)) => {
let crc32 = self.stats.hasher.clone().finalize();
self.inner = GenericZipWriter::Storer(MaybeEncrypted::Unencrypted(writer.finish(crc32)?))
self.inner =
GenericZipWriter::Storer(MaybeEncrypted::Unencrypted(writer.finish(crc32)?))
}
GenericZipWriter::Storer(w) => self.inner = GenericZipWriter::Storer(w),
_ => unreachable!()
_ => unreachable!(),
}
let writer = self.inner.get_plain();

Expand Down
10 changes: 7 additions & 3 deletions tests/zip_crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,16 @@ use std::io::Read;

#[test]
fn encrypting_file() {
use zip::unstable::write::FileOptionsExt;
use std::io::{Read, Write};
use zip::unstable::write::FileOptionsExt;
let mut buf = vec![0; 2048];
let mut archive = zip::write::ZipWriter::new(std::io::Cursor::new(&mut buf));
archive.start_file("name", zip::write::FileOptions::default().with_deprecated_encryption(b"password")).unwrap();
archive
.start_file(
"name",
zip::write::FileOptions::default().with_deprecated_encryption(b"password"),
)
.unwrap();
archive.write_all(b"test").unwrap();
archive.finish().unwrap();
drop(archive);
Expand All @@ -35,7 +40,6 @@ fn encrypting_file() {
let mut buf = Vec::new();
file.read_to_end(&mut buf).unwrap();
assert_eq!(buf, b"test");

}
#[test]
fn encrypted_file() {
Expand Down

0 comments on commit 682a9ba

Please sign in to comment.