Fix merge
This commit is contained in:
parent
5bb40012d2
commit
9efec6b61f
2 changed files with 10 additions and 12 deletions
20
src/write.rs
20
src/write.rs
|
@ -475,8 +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 { writer: core::mem::replace(&mut self.inner, GenericZipWriter::Closed).unwrap(), buffer: vec![], keys };
|
let mut zipwriter = crate::zipcrypto::ZipCryptoWriter { writer: mem::replace(&mut self.inner, Closed).unwrap(), buffer: vec![], keys };
|
||||||
let mut crypto_header = [0u8; 12];
|
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));
|
||||||
|
@ -505,15 +505,9 @@ 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 = match self
|
let make_plain_writer = 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();
|
||||||
|
|
||||||
|
@ -1036,12 +1030,14 @@ impl<W: Write + Seek> Drop for ZipWriter<W> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type SwitchWriterFunction<W> = Box<dyn FnOnce(MaybeEncrypted<W>) -> GenericZipWriter<W>>;
|
||||||
|
|
||||||
impl<W: Write + Seek> GenericZipWriter<W> {
|
impl<W: Write + Seek> GenericZipWriter<W> {
|
||||||
fn prepare_next_writer(
|
fn prepare_next_writer(
|
||||||
&self,
|
&self,
|
||||||
compression: CompressionMethod,
|
compression: CompressionMethod,
|
||||||
compression_level: Option<i32>,
|
compression_level: Option<i32>,
|
||||||
) -> ZipResult<Box<dyn FnOnce(MaybeEncrypted<W>) -> GenericZipWriter<W>>> {
|
) -> ZipResult<SwitchWriterFunction<W>> {
|
||||||
if let Closed = self {
|
if let Closed = self {
|
||||||
return Err(
|
return Err(
|
||||||
io::Error::new(io::ErrorKind::BrokenPipe, "ZipWriter was already closed").into(),
|
io::Error::new(io::ErrorKind::BrokenPipe, "ZipWriter was already closed").into(),
|
||||||
|
@ -1121,7 +1117,7 @@ impl<W: Write + Seek> GenericZipWriter<W> {
|
||||||
|
|
||||||
fn switch_to(
|
fn switch_to(
|
||||||
&mut self,
|
&mut self,
|
||||||
make_new_self: Box<dyn FnOnce(MaybeEncrypted<W>) -> GenericZipWriter<W>>,
|
make_new_self: SwitchWriterFunction<W>,
|
||||||
) -> ZipResult<()> {
|
) -> ZipResult<()> {
|
||||||
let bare = match mem::replace(self, Closed) {
|
let bare = match mem::replace(self, Closed) {
|
||||||
Storer(w) => w,
|
Storer(w) => w,
|
||||||
|
|
|
@ -135,12 +135,14 @@ impl<R: std::io::Read> ZipCryptoReader<R> {
|
||||||
Ok(Some(ZipCryptoReaderValid { reader: self }))
|
Ok(Some(ZipCryptoReaderValid { reader: self }))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#[allow(unused)]
|
||||||
pub(crate) struct ZipCryptoWriter<W> {
|
pub(crate) struct ZipCryptoWriter<W> {
|
||||||
pub(crate) writer: W,
|
pub(crate) writer: W,
|
||||||
pub(crate) buffer: Vec<u8>,
|
pub(crate) buffer: Vec<u8>,
|
||||||
pub(crate) keys: ZipCryptoKeys,
|
pub(crate) keys: ZipCryptoKeys,
|
||||||
}
|
}
|
||||||
impl<W: std::io::Write> ZipCryptoWriter<W> {
|
impl<W: std::io::Write> ZipCryptoWriter<W> {
|
||||||
|
#[allow(unused)]
|
||||||
pub(crate) fn finish(mut self, crc32: u32) -> std::io::Result<W> {
|
pub(crate) fn finish(mut self, crc32: u32) -> std::io::Result<W> {
|
||||||
self.buffer[11] = (crc32 >> 24) as u8;
|
self.buffer[11] = (crc32 >> 24) as u8;
|
||||||
for byte in self.buffer.iter_mut() {
|
for byte in self.buffer.iter_mut() {
|
||||||
|
|
Loading…
Add table
Reference in a new issue