1#[rustfmt::skip]
6#[repr(u16)]
7#[derive(Debug, Copy, Clone, PartialEq, Eq)]
8#[non_exhaustive]
9pub enum ZipFlags {
10 Encrypted = 0b0000_0000_0000_0001,
12 #[allow(unused)]
14 CompressionSetting = 0b0000_0000_0000_0010,
15 #[allow(unused)]
17 CompressionSetting2 = 0b0000_0000_0000_0100,
18 UsingDataDescriptor = 0b0000_0000_0000_1000,
21 #[allow(unused)]
23 ReservedEnhancedDeflating = 0b0000_0000_0001_0000,
24 #[allow(unused)]
26 CompressedPatchedData = 0b0000_0000_0010_0000,
27 #[allow(unused)]
31 StrongEncryption = 0b0000_0000_0100_0000,
32 LanguageEncoding = 0b0000_1000_0000_0000,
40 #[allow(unused)]
42 ReservedEnhancedCompression = 0b0001_0000_0000_0000,
43 #[allow(unused)]
45 Masked = 0b0010_0000_0000_0000,
46 #[allow(unused)]
48 ReservedAlternateStream = 0b0100_0000_0000_0000,
49 #[allow(unused)]
51 Reserved = 0b1000_0000_0000_0000,
52}
53
54impl ZipFlags {
55 #[inline]
56 pub(crate) fn matching(flags: u16, matching_flag: Self) -> bool {
57 flags & u16::from(matching_flag) != 0
58 }
59
60 #[inline]
61 pub(crate) const fn as_u16(self) -> u16 {
62 self as u16
63 }
64}
65
66impl From<ZipFlags> for u16 {
67 fn from(value: ZipFlags) -> u16 {
68 value.as_u16()
69 }
70}
71
72#[repr(transparent)]
74#[derive(Clone, Copy, Debug, PartialEq, Eq, Default)]
75pub struct ZipFileFlags(pub(crate) u16);
76
77impl ZipFileFlags {
78 #[inline]
80 #[must_use]
81 pub fn matching(&self, matching_flag: ZipFlags) -> bool {
82 ZipFlags::matching(self.0, matching_flag)
83 }
84
85 #[inline]
87 #[must_use]
88 pub fn is_encrypted(&self) -> bool {
89 self.matching(ZipFlags::Encrypted)
90 }
91
92 #[inline]
94 #[must_use]
95 pub fn is_using_data_descriptor(&self) -> bool {
96 self.matching(ZipFlags::UsingDataDescriptor)
97 }
98
99 #[inline]
101 #[must_use]
102 pub const fn as_u16(self) -> u16 {
103 self.0
104 }
105}
106
107impl From<u16> for ZipFileFlags {
108 fn from(value: u16) -> Self {
109 ZipFileFlags(value)
110 }
111}
112
113impl core::ops::BitOrAssign<u16> for ZipFileFlags {
114 fn bitor_assign(&mut self, rhs: u16) {
115 self.0 |= rhs;
116 }
117}