1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
//! Flags of zip
/// Zip flags
/// Stored as Little endian
#[rustfmt::skip]
#[repr(u16)]
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum ZipFlags {
/// If set, indicates that the file is encrypted.
Encrypted = 0b0000_0000_0000_0001,
/// Compression setting
#[allow(unused)]
CompressionSetting = 0b0000_0000_0000_0010,
/// Compression setting 2
#[allow(unused)]
CompressionSetting2 = 0b0000_0000_0000_0100,
/// If this bit is set, the fields crc-32, compressed size and uncompressed size are set to zero in the local header.
/// The correct values are put in the data descriptor immediately following the compressed data.
UsingDataDescriptor = 0b0000_0000_0000_1000,
/// Reserved for use with method 8, for enhanced deflating.
#[allow(unused)]
ReservedEnhancedDeflating = 0b0000_0000_0001_0000,
/// If this bit is set, this indicates that the file is compressed patched data.
#[allow(unused)]
CompressedPatchedData = 0b0000_0000_0010_0000,
/// Strong encryption.
/// If this bit is set, you MUST set the version needed to extract value to at least 50 and you MUST also set bit 0.
/// If AES encryption is used, the version needed to extract value MUST be at least 51.
#[allow(unused)]
StrongEncryption = 0b0000_0000_0100_0000,
// bit 7 Currently unused = 0b0000_0000_1000_0000;
// bit 8 Currently unused = 0b0000_0001_0000_0000;
// bit 9 Currently unused = 0b0000_0010_0000_0000;
// bit 10 Currently unused = 0b0000_0100_0000_0000;
/// Language encoding flag (EFS).
/// If this bit is set, the filename and comment fields for this file MUST be encoded using UTF-8.
LanguageEncoding = 0b0000_1000_0000_0000,
/// Reserved by PKWARE for enhanced compression.
#[allow(unused)]
ReservedEnhancedCompression = 0b0001_0000_0000_0000,
/// Set when encrypting the Central Directory to indicate selected data values in the Local Header are masked to hide their actual values.
#[allow(unused)]
Masked = 0b0010_0000_0000_0000,
/// Reserved by PKWARE for alternate streams.
#[allow(unused)]
ReservedAlternateStream = 0b0100_0000_0000_0000,
/// Reserved by PKWARE.
#[allow(unused)]
Reserved = 0b1000_0000_0000_0000,
}
impl ZipFlags {
#[inline]
pub(crate) fn matching(flags: u16, matching_flag: Self) -> bool {
flags & u16::from(matching_flag) != 0
}
#[inline]
pub(crate) const fn as_u16(self) -> u16 {
self as u16
}
}
impl From<ZipFlags> for u16 {
fn from(value: ZipFlags) -> u16 {
value.as_u16()
}
}
/// Zip flags
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Default)]
pub struct ZipFileFlags(pub(crate) u16);
impl ZipFileFlags {
/// Check if flags are matching a specific `ZipFlags`
#[inline]
#[must_use]
pub fn matching(&self, matching_flag: ZipFlags) -> bool {
ZipFlags::matching(self.0, matching_flag)
}
/// Check if the encrypted flag is set
#[inline]
#[must_use]
pub fn is_encrypted(&self) -> bool {
self.matching(ZipFlags::Encrypted)
}
/// Check if the data descriptor flag is set
#[inline]
#[must_use]
pub fn is_using_data_descriptor(&self) -> bool {
self.matching(ZipFlags::UsingDataDescriptor)
}
/// Get the inner value
#[inline]
#[must_use]
pub const fn as_u16(self) -> u16 {
self.0
}
}
impl From<u16> for ZipFileFlags {
fn from(value: u16) -> Self {
ZipFileFlags(value)
}
}
impl core::ops::BitOrAssign<u16> for ZipFileFlags {
fn bitor_assign(&mut self, rhs: u16) {
self.0 |= rhs;
}
}