aboutsummaryrefslogtreecommitdiff
path: root/src/zip
diff options
context:
space:
mode:
Diffstat (limited to 'src/zip')
-rw-r--r--src/zip/cp437.rs2
-rw-r--r--src/zip/encryption.rs22
-rw-r--r--src/zip/error.rs2
-rw-r--r--src/zip/structs.rs2
4 files changed, 16 insertions, 12 deletions
diff --git a/src/zip/cp437.rs b/src/zip/cp437.rs
index 6f6731a..91a3c00 100644
--- a/src/zip/cp437.rs
+++ b/src/zip/cp437.rs
@@ -343,6 +343,7 @@ pub fn is_cp437(char: char) -> bool {
343impl FromCp437<Vec<u8>> for String { 343impl FromCp437<Vec<u8>> for String {
344 type Value = Self; 344 type Value = Self;
345 345
346 #[inline]
346 fn from_cp437(bytes: Vec<u8>) -> Self { 347 fn from_cp437(bytes: Vec<u8>) -> Self {
347 Self::from_cp437(bytes.as_slice()) 348 Self::from_cp437(bytes.as_slice())
348 } 349 }
@@ -351,6 +352,7 @@ impl FromCp437<Vec<u8>> for String {
351impl<const S: usize> FromCp437<[u8; S]> for String { 352impl<const S: usize> FromCp437<[u8; S]> for String {
352 type Value = Self; 353 type Value = Self;
353 354
355 #[inline]
354 fn from_cp437(bytes: [u8; S]) -> Self { 356 fn from_cp437(bytes: [u8; S]) -> Self {
355 Self::from_cp437(bytes.as_slice()) 357 Self::from_cp437(bytes.as_slice())
356 } 358 }
diff --git a/src/zip/encryption.rs b/src/zip/encryption.rs
index 76824a1..f317245 100644
--- a/src/zip/encryption.rs
+++ b/src/zip/encryption.rs
@@ -7,22 +7,22 @@ const TABLE: [u32; 256] = generate_table();
7const fn generate_table() -> [u32; 256] { 7const fn generate_table() -> [u32; 256] {
8 let mut table = [0; 256]; 8 let mut table = [0; 256];
9 9
10 let mut b = 0; 10 let mut i = 0;
11 while b <= 255 { 11 while i <= 255 {
12 let mut crc = b as u32; 12 let mut t = i as u32;
13 13
14 let mut i = 0; 14 let mut j = 0;
15 while i < 8 { 15 while j < 8 {
16 if (crc & 1) > 0 { 16 if (t & 1) > 0 {
17 crc = (crc >> 1) ^ 0xEDB88320 17 t = (t >> 1) ^ 0xEDB88320
18 } else { 18 } else {
19 crc >>= 1 19 t >>= 1
20 } 20 }
21 i += 1; 21 j += 1;
22 } 22 }
23 23
24 table[b] = crc; 24 table[i] = t;
25 b += 1 25 i += 1
26 } 26 }
27 27
28 table 28 table
diff --git a/src/zip/error.rs b/src/zip/error.rs
index 525a67b..5573cf8 100644
--- a/src/zip/error.rs
+++ b/src/zip/error.rs
@@ -29,7 +29,7 @@ pub enum ZipError {
29impl From<ZipError> for ArchiveError<ZipError> { 29impl From<ZipError> for ArchiveError<ZipError> {
30 fn from(value: ZipError) -> Self { 30 fn from(value: ZipError) -> Self {
31 Self::Archivator { 31 Self::Archivator {
32 module: "Zip".to_string(), 32 module: "Zip",
33 error: value, 33 error: value,
34 } 34 }
35 } 35 }
diff --git a/src/zip/structs.rs b/src/zip/structs.rs
index 9fd1aeb..ebecae7 100644
--- a/src/zip/structs.rs
+++ b/src/zip/structs.rs
@@ -58,11 +58,13 @@ pub struct ExtraHeader {
58 pub size: u16, 58 pub size: u16,
59} 59}
60 60
61#[inline]
61#[allow(dead_code)] 62#[allow(dead_code)]
62pub fn serialize<T: Serialize>(object: &mut T) -> StructResult<Vec<u8>> { 63pub fn serialize<T: Serialize>(object: &mut T) -> StructResult<Vec<u8>> {
63 Settings::new(ByteOrder::Le, VariantIndexType::U8).serialize(object) 64 Settings::new(ByteOrder::Le, VariantIndexType::U8).serialize(object)
64} 65}
65 66
67#[inline]
66pub fn deserialize<'de, T: Deserialize<'de>>(object: &'de [u8]) -> StructResult<T> { 68pub fn deserialize<'de, T: Deserialize<'de>>(object: &'de [u8]) -> StructResult<T> {
67 Settings::new(ByteOrder::Le, VariantIndexType::U8).deserialize(object) 69 Settings::new(ByteOrder::Le, VariantIndexType::U8).deserialize(object)
68} 70}