From 7530ce50007cbeaadd73acfb773029ec8c78af4f Mon Sep 17 00:00:00 2001 From: Chris Hennick <4961925+Pr0methean@users.noreply.github.com> Date: Sun, 2 Jun 2024 11:56:46 -0700 Subject: [PATCH] style: Cargo fmt --all --- src/extra_fields/zipinfo_utf8.rs | 20 ++++++++++---------- src/read.rs | 15 +++++++++++---- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/extra_fields/zipinfo_utf8.rs b/src/extra_fields/zipinfo_utf8.rs index f8e360fa..c8ae6d0d 100644 --- a/src/extra_fields/zipinfo_utf8.rs +++ b/src/extra_fields/zipinfo_utf8.rs @@ -1,14 +1,14 @@ -use core::mem::size_of; -use std::io::Read; use crate::result::{ZipError, ZipResult}; use crate::unstable::LittleEndianReadExt; +use core::mem::size_of; +use std::io::Read; /// Info-ZIP Unicode Path Extra Field (0x7075) or Unicode Comment Extra Field (0x6375), as /// specified in APPNOTE 4.6.8 and 4.6.9 #[derive(Clone, Debug)] pub struct UnicodeExtraField { crc32: u32, - content: Box<[u8]> + content: Box<[u8]>, } impl<'a> UnicodeExtraField { @@ -18,7 +18,9 @@ impl<'a> UnicodeExtraField { crc32.update(ascii_field); let actual_crc32 = crc32.finalize(); if self.crc32 != actual_crc32 { - return Err(ZipError::InvalidArchive("CRC32 checksum failed on Unicode extra field")); + return Err(ZipError::InvalidArchive( + "CRC32 checksum failed on Unicode extra field", + )); } Ok(self.content) } @@ -30,11 +32,9 @@ impl UnicodeExtraField { reader.read_exact(&mut [0u8])?; let crc32 = reader.read_u32_le()?; - let mut content = vec![0u8; len as usize - size_of::() - size_of::()].into_boxed_slice(); + let mut content = + vec![0u8; len as usize - size_of::() - size_of::()].into_boxed_slice(); reader.read_exact(&mut content)?; - Ok(Self { - crc32, - content - }) + Ok(Self { crc32, content }) } -} \ No newline at end of file +} diff --git a/src/read.rs b/src/read.rs index 6d9f441d..83d3db33 100644 --- a/src/read.rs +++ b/src/read.rs @@ -95,6 +95,7 @@ pub(crate) mod zip_archive { #[cfg(feature = "aes-crypto")] use crate::aes::PWD_VERIFY_LENGTH; +use crate::extra_fields::UnicodeExtraField; #[cfg(feature = "lzma")] use crate::read::lzma::LzmaDecoder; use crate::result::ZipError::{InvalidPassword, UnsupportedArchive}; @@ -102,7 +103,6 @@ use crate::spec::{is_dir, path_to_string}; use crate::types::ffi::S_IFLNK; use crate::unstable::LittleEndianReadExt; pub use zip_archive::ZipArchive; -use crate::extra_fields::UnicodeExtraField; #[allow(clippy::large_enum_variant)] pub(crate) enum CryptoReader<'a> { @@ -1286,15 +1286,22 @@ fn parse_extra_field(file: &mut ZipFileData) -> ZipResult<()> { // APPNOTE 4.6.8 and https://libzip.org/specifications/extrafld.txt if !file.is_utf8 { file.file_comment = String::from_utf8( - UnicodeExtraField::try_from_reader(&mut reader, len)?.unwrap_valid(file.file_comment.as_bytes())?.into_vec())?.into(); + UnicodeExtraField::try_from_reader(&mut reader, len)? + .unwrap_valid(file.file_comment.as_bytes())? + .into_vec(), + )? + .into(); } } 0x7075 => { // Info-ZIP Unicode Path Extra Field // APPNOTE 4.6.9 and https://libzip.org/specifications/extrafld.txt if !file.is_utf8 { - file.file_name_raw = UnicodeExtraField::try_from_reader(&mut reader, len)?.unwrap_valid(&file.file_name_raw)?; - file.file_name = String::from_utf8(file.file_name_raw.clone().into_vec())?.into_boxed_str(); + file.file_name_raw = UnicodeExtraField::try_from_reader(&mut reader, len)? + .unwrap_valid(&file.file_name_raw)?; + file.file_name = + String::from_utf8(file.file_name_raw.clone().into_vec())?.into_boxed_str(); + file.is_utf8 = true; } } _ => {