aboutsummaryrefslogtreecommitdiff
path: root/src/zip/file/info.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/zip/file/info.rs')
-rw-r--r--src/zip/file/info.rs47
1 files changed, 34 insertions, 13 deletions
diff --git a/src/zip/file/info.rs b/src/zip/file/info.rs
index 4e1b293..f5d4d8a 100644
--- a/src/zip/file/info.rs
+++ b/src/zip/file/info.rs
@@ -2,7 +2,7 @@ use crate::driver::ArchiveFileInfo;
2use crate::zip::{ZipError, ZipResult}; 2use crate::zip::{ZipError, ZipResult};
3use chrono::{DateTime, Local}; 3use chrono::{DateTime, Local};
4 4
5#[derive(Debug, Clone)] 5#[derive(Debug, PartialEq, Eq, Clone, Copy)]
6pub enum CompressionMethod { 6pub enum CompressionMethod {
7 Store, 7 Store,
8 Deflate, 8 Deflate,
@@ -10,31 +10,49 @@ pub enum CompressionMethod {
10 Lzma, 10 Lzma,
11 Zstd, 11 Zstd,
12 Xz, 12 Xz,
13 Unsupported, 13 Unsupported(u16),
14} 14}
15 15
16impl CompressionMethod { 16impl CompressionMethod {
17 pub(crate) fn from_struct_id(id: u16) -> ZipResult<Self> { 17 pub(crate) fn from_struct_id(id: u16) -> ZipResult<Self> {
18 match id { 18 Ok(match id {
19 0 => Ok(Self::Store), 19 0 => Self::Store,
20 8 => Ok(Self::Deflate), 20 8 => Self::Deflate,
21 12 => Ok(Self::BZip2), 21 12 => Self::BZip2,
22 14 => Ok(Self::Lzma), 22 14 => Self::Lzma,
23 93 => Ok(Self::Zstd), 23 93 => Self::Zstd,
24 95 => Ok(Self::Xz), 24 95 => Self::Xz,
25 1..=7 | 9..=11 | 13 | 15..=20 | 94 | 96..=99 => Ok(Self::Unsupported), 25 1..=7 | 9..=11 | 13 | 15..=20 | 94 | 96..=99 => Self::Unsupported(id),
26 21..=92 | 100.. => Err(ZipError::InvalidCompressionMethod.into()), 26 21..=92 | 100.. => return Err(ZipError::InvalidCompressionMethod(id).into()),
27 })
28 }
29}
30
31#[derive(Debug, PartialEq, Eq, Clone, Copy)]
32pub enum EncryptionMethod {
33 None,
34 Weak,
35 Unsupported,
36}
37
38impl EncryptionMethod {
39 pub(crate) fn from_bit_flag(bit_flag: BitFlag) -> EncryptionMethod {
40 match (bit_flag.is_encrypted(), bit_flag.is_strong_encryption()) {
41 (false, false) => EncryptionMethod::None,
42 (true, false) => EncryptionMethod::Weak,
43 (true, true) => EncryptionMethod::Unsupported,
44 _ => panic!("impossible"),
27 } 45 }
28 } 46 }
29} 47}
30 48
31#[derive(Debug, Clone)] 49#[derive(Debug, PartialEq, Eq, Clone, Copy)]
32pub struct BitFlag { 50pub struct BitFlag {
33 flag: u16, 51 flag: u16,
34} 52}
35 53
36pub mod bit { 54pub mod bit {
37 #[derive(Debug, PartialEq, Eq)] 55 #[derive(Debug, PartialEq, Eq, Clone, Copy)]
38 pub enum DeflateMode { 56 pub enum DeflateMode {
39 Normal, 57 Normal,
40 Maximum, 58 Maximum,
@@ -123,6 +141,7 @@ impl BitFlag {
123#[derive(Debug, Clone)] 141#[derive(Debug, Clone)]
124pub struct ZipFileInfo { 142pub struct ZipFileInfo {
125 pub compression_method: CompressionMethod, 143 pub compression_method: CompressionMethod,
144 pub encryption_method: EncryptionMethod,
126 pub bit_flag: BitFlag, 145 pub bit_flag: BitFlag,
127 pub mtime: DateTime<Local>, 146 pub mtime: DateTime<Local>,
128 pub atime: Option<DateTime<Local>>, 147 pub atime: Option<DateTime<Local>>,
@@ -138,6 +157,7 @@ pub struct ZipFileInfo {
138impl ZipFileInfo { 157impl ZipFileInfo {
139 pub fn new( 158 pub fn new(
140 compression_method: CompressionMethod, 159 compression_method: CompressionMethod,
160 encryption_method: EncryptionMethod,
141 bit_flag: BitFlag, 161 bit_flag: BitFlag,
142 mtime: DateTime<Local>, 162 mtime: DateTime<Local>,
143 atime: Option<DateTime<Local>>, 163 atime: Option<DateTime<Local>>,
@@ -151,6 +171,7 @@ impl ZipFileInfo {
151 ) -> Self { 171 ) -> Self {
152 Self { 172 Self {
153 compression_method, 173 compression_method,
174 encryption_method,
154 bit_flag, 175 bit_flag,
155 mtime, 176 mtime,
156 atime, 177 atime,