WIP: Fix upstream merge

This commit is contained in:
Chris Hennick 2023-05-08 19:37:55 -07:00
parent b179709639
commit 5bb40012d2
No known key found for this signature in database
GPG key ID: 25653935CC8B6C74
2 changed files with 11 additions and 9 deletions

View file

@ -57,7 +57,7 @@ pub(crate) mod zip_archive {
/// for i in 0..zip.len() { /// for i in 0..zip.len() {
/// let mut file = zip.by_index(i)?; /// let mut file = zip.by_index(i)?;
/// println!("Filename: {}", file.name()); /// println!("Filename: {}", file.name());
/// std::io::copy(&mut file, &mut std::io::stdout()); /// std::io::copy(&mut file, &mut std::io::stdout())?;
/// } /// }
/// ///
/// Ok(()) /// Ok(())

View file

@ -475,12 +475,8 @@ impl<W: Write + Seek> ZipWriter<W> {
self.stats.hasher = Hasher::new(); self.stats.hasher = Hasher::new();
} }
if let Some(keys) = options.encrypt_with { if let Some(keys) = options.encrypt_with {
let mut zipwriter = crate::zipcrypto::ZipCryptoWriter { let mut zipwriter = crate::zipcrypto::ZipCryptoWriter { writer: core::mem::replace(&mut self.inner, GenericZipWriter::Closed).unwrap(), buffer: vec![], keys };
writer: mem::replace(&mut self.inner, Closed).unwrap(), let mut crypto_header = [0u8; 12];
buffer: vec![],
keys,
};
let crypto_header = [0u8; 12];
zipwriter.write_all(&crypto_header)?; zipwriter.write_all(&crypto_header)?;
self.inner = Storer(MaybeEncrypted::Encrypted(zipwriter)); self.inner = Storer(MaybeEncrypted::Encrypted(zipwriter));
@ -509,9 +505,15 @@ impl<W: Write + Seek> ZipWriter<W> {
// Implicitly calling [`ZipWriter::end_extra_data`] for empty files. // Implicitly calling [`ZipWriter::end_extra_data`] for empty files.
self.end_extra_data()?; self.end_extra_data()?;
} }
let make_plain_writer = self let make_plain_writer = match self
.inner .inner
.prepare_next_writer(CompressionMethod::Stored, None)?; .prepare_next_writer(CompressionMethod::Stored, None)? {
MaybeEncrypted::Encrypted(writer) => {
let crc32 = self.stats.hasher.clone().finalize();
self.inner = Storer(MaybeEncrypted::Unencrypted(writer.finish(crc32)?))
},
MaybeEncrypted::Unencrypted(writer) => writer
}
self.inner.switch_to(make_plain_writer)?; self.inner.switch_to(make_plain_writer)?;
let writer = self.inner.get_plain(); let writer = self.inner.get_plain();