1- //! types for extra fields
1+ //! Types for extra fields
22
33/// marker trait to denote the place where this extra field has been stored
44pub trait ExtraFieldVersion { }
@@ -20,6 +20,7 @@ mod extended_timestamp;
2020mod ntfs;
2121mod zipinfo_utf8;
2222
23+ // re-export
2324pub use extended_timestamp:: * ;
2425pub use ntfs:: Ntfs ;
2526pub use zipinfo_utf8:: UnicodeExtraField ;
@@ -33,3 +34,116 @@ pub enum ExtraField {
3334 /// extended timestamp, as described in <https://libzip.org/specifications/extrafld.txt>
3435 ExtendedTimestamp ( ExtendedTimestamp ) ,
3536}
37+
38+ /// Extra field used in this crate
39+ #[ repr( u16 ) ]
40+ #[ derive( Debug , Copy , Clone , PartialEq , Eq ) ]
41+ pub ( crate ) enum UsedExtraField {
42+ /// ZIP64 extended information extra field
43+ Zip64ExtendedInfo = 0x0001 ,
44+ /// NTFS
45+ Ntfs = 0x000a ,
46+ /// extended timestamp
47+ /// from https://libzip.org/specifications/extrafld.txt
48+ ExtendedTimestamp = 0x5455 ,
49+ /// Info-ZIP Unicode Comment Extra Field
50+ UnicodeComment = 0x6375 ,
51+ /// Info-ZIP Unicode Path Extra Field
52+ UnicodePath = 0x7075 ,
53+ /// AE-x encryption structure
54+ AeXEncryption = 0x9901 ,
55+ /// Data Stream Alignment (Apache Commons-Compress)
56+ DataStreamAlignement = 0xa11e ,
57+ }
58+
59+ macro_rules! extra_field_match {
60+ ( $x: expr, $( $variant: path ) ,+ $( , ) ?) => {
61+ match $x {
62+ $(
63+ v if v == $variant as u16 => Ok ( $variant) ,
64+ ) +
65+ _ => Err ( ( ) ) ,
66+ }
67+ } ;
68+ }
69+
70+ impl TryFrom < u16 > for UsedExtraField {
71+ type Error = ( ) ;
72+
73+ fn try_from ( value : u16 ) -> Result < Self , Self :: Error > {
74+ extra_field_match ! (
75+ value,
76+ UsedExtraField :: Zip64ExtendedInfo ,
77+ UsedExtraField :: Ntfs ,
78+ UsedExtraField :: ExtendedTimestamp ,
79+ UsedExtraField :: UnicodeComment ,
80+ UsedExtraField :: UnicodePath ,
81+ UsedExtraField :: DataStreamAlignement ,
82+ UsedExtraField :: AeXEncryption ,
83+ )
84+ }
85+ }
86+ // AE-x encryption structure
87+
88+ /// Known Extra fields (PKWARE and Third party) mappings
89+ pub const EXTRA_FIELD_MAPPING : [ u16 ; 58 ] = [
90+ UsedExtraField :: Zip64ExtendedInfo as u16 ,
91+ 0x0007 , // AV Info
92+ 0x0008 , // Reserved for extended language encoding data (PFS)
93+ 0x0009 , // OS/2
94+ UsedExtraField :: Ntfs as u16 ,
95+ 0x000c , // OpenVMS
96+ 0x000d , // UNIX
97+ 0x000e , // Reserved for file stream and fork descriptors
98+ 0x000f , // Patch Descriptor
99+ 0x0014 , // PKCS#7 Store for X.509 Certificates
100+ 0x0015 , // X.509 Certificate ID and Signature for individual file
101+ 0x0016 , // X.509 Certificate ID for Central Directory
102+ 0x0017 , // Strong Encryption Header
103+ 0x0018 , // Record Management Controls
104+ 0x0019 , // PKCS#7 Encryption Recipient Certificate List
105+ 0x0020 , // Reserved for Timestamp record
106+ 0x0021 , // Policy Decryption Key Record
107+ 0x0022 , // Smartcrypt Key Provider Record
108+ 0x0023 , // Smartcrypt Policy Key Data Record
109+ 0x0065 , // IBM S/390 (Z390), AS/400 (I400) attributes - uncompressed
110+ 0x0066 , // Reserved for IBM S/390 (Z390), AS/400 (I400) attributes - compressed
111+ 0x4690 , // POSZIP 4690 (reserved)
112+ // Third party mappings commonly used
113+ 0x07c8 , // Macintosh
114+ 0x1986 , // Pixar USD header ID
115+ 0x2605 , // ZipIt Macintosh
116+ 0x2705 , // ZipIt Macintosh 1.3.5+
117+ 0x2805 , // ZipIt Macintosh 1.3.5+
118+ 0x334d , // Info-ZIP Macintosh
119+ 0x4154 , // Tandem
120+ 0x4341 , // Acorn/SparkFS
121+ 0x4453 , // Windows NT security descriptor (binary ACL)
122+ 0x4704 , // VM/CMS
123+ 0x470f , // MVS
124+ 0x4854 , // THEOS (old?)
125+ 0x4b46 , // FWKCS MD5
126+ 0x4c41 , // OS/2 access control list (text ACL)
127+ 0x4d49 , // Info-ZIP OpenVMS
128+ 0x4d63 , // Macintosh Smartzip (??)
129+ 0x4f4c , // Xceed original location extra field
130+ 0x5356 , // AOS/VS (ACL)
131+ 0x554e , // Xceed unicode extra field
132+ 0x5855 , // Info-ZIP UNIX (original, also OS/2, NT, etc)
133+ UsedExtraField :: UnicodeComment as u16 ,
134+ 0x6542 , // BeOS/BeBox
135+ 0x6854 , // THEOS
136+ UsedExtraField :: UnicodePath as u16 ,
137+ 0x7441 , // AtheOS/Syllable
138+ 0x756e , // ASi UNIX
139+ 0x7855 , // Info-ZIP UNIX (new)
140+ 0x7875 , // Info-ZIP UNIX (newer UID/GID)
141+ UsedExtraField :: DataStreamAlignement as u16 ,
142+ 0xa220 , // Microsoft Open Packaging Growth Hint
143+ 0xcafe , // Java JAR file Extra Field Header ID
144+ 0xd935 , // Android ZIP Alignment Extra Field
145+ 0xe57a , // Korean ZIP code page info
146+ 0xfd4a , // SMS/QDOS
147+ UsedExtraField :: AeXEncryption as u16 ,
148+ 0x9902 , // unknown
149+ ] ;
0 commit comments