Skip to main content

zip_framing/
constants.rs

1//! ZIP wire-format values shared by record parsing, serialization, and codecs.
2//!
3//! These identify fields and features; they do not imply support for them.
4//! See the [PKWARE APPNOTE 6.3.9](https://pkwaredownloads.blob.core.windows.net/pkware-general/Documentation/APPNOTE-6.3.9.TXT).
5
6/// Record signatures (APPNOTE section 4.3).
7pub mod signature {
8    /// Local file header.
9    pub const LOCAL: u32 = 0x0403_4b50;
10    /// Central directory file header.
11    pub const CENTRAL: u32 = 0x0201_4b50;
12    /// Optional data descriptor signature.
13    pub const DESCRIPTOR: u32 = 0x0807_4b50;
14    /// End of central directory.
15    pub const END: u32 = 0x0605_4b50;
16    /// ZIP64 end of central directory.
17    pub const ZIP64_END: u32 = 0x0606_4b50;
18    /// ZIP64 end of central directory locator.
19    pub const ZIP64_LOCATOR: u32 = 0x0706_4b50;
20    /// Archive extra data record.
21    pub const ARCHIVE_EXTRA: u32 = 0x0806_4b50;
22}
23
24/// Fixed record lengths in bytes, excluding variable data (APPNOTE section 4.3).
25pub mod size {
26    /// Record signature.
27    pub const SIGNATURE: usize = 4;
28    /// Local file header, including its signature.
29    pub const LOCAL: usize = 30;
30    /// Central directory file header, including its signature.
31    pub const CENTRAL: usize = 46;
32    /// Classic data descriptor without a signature.
33    pub const DESCRIPTOR: usize = 12;
34    /// ZIP64 data descriptor without a signature.
35    pub const ZIP64_DESCRIPTOR: usize = 20;
36    /// End of central directory, including its signature.
37    pub const END: usize = 22;
38    /// ZIP64 end record signature and size field, excluded from its declared size.
39    pub const ZIP64_END_PREFIX: usize = 12;
40    /// ZIP64 version-1 end record body, excluding extensible data.
41    pub const ZIP64_END_BODY: usize = 44;
42    /// ZIP64 version-1 end record, including its signature and size field.
43    pub const ZIP64_END: usize = ZIP64_END_PREFIX + ZIP64_END_BODY;
44    /// ZIP64 end of central directory locator, including its signature.
45    pub const ZIP64_LOCATOR: usize = 20;
46    /// Archive extra data record header, including its signature.
47    pub const ARCHIVE_EXTRA: usize = 8;
48    /// ZIP64 extensible data sector field header (two-byte ID, four-byte size).
49    pub const ZIP64_EXTENSION: usize = 6;
50}
51
52/// Extra-field layouts (APPNOTE sections 4.5 and 4.6).
53///
54/// Header identifiers are represented by [`crate::ExtraHeaderId`].
55pub mod extra {
56    /// Extra-field header length in bytes (two-byte ID, two-byte size).
57    pub const HEADER_SIZE: usize = 4;
58    /// PKWARE UNIX timestamp and ownership prefix length in bytes.
59    pub const UNIX_PREFIX_SIZE: usize = 12;
60    /// ZIP64 local extra data length in bytes (both sizes).
61    pub const ZIP64_LOCAL_SIZE: usize = 16;
62    /// ZIP64 central extra data length in bytes when both sizes and the offset are present.
63    pub const ZIP64_CENTRAL_SIZE: usize = 24;
64}
65
66/// Extraction versions, encoded as major version times ten plus minor version.
67pub mod version {
68    /// ZIP 1.0, the baseline extraction version.
69    pub const BASE: u16 = 10;
70    /// ZIP 1.1, required for DOS volume labels.
71    pub const V1_1: u16 = 11;
72    /// ZIP 2.0, required for DEFLATE and directory entries.
73    pub const V2_0: u16 = 20;
74    /// ZIP 4.5, required for ZIP64.
75    pub const ZIP64: u16 = 45;
76    /// ZIP 6.2, introducing encrypted central directories and ZIP64 version-2 end records.
77    pub const ZIP64_V2: u16 = 62;
78}
79
80/// UNIX permission bits carried in external file attributes.
81pub mod attributes {
82    /// Any UNIX execute permission.
83    pub const UNIX_EXECUTABLE: u16 = 0o111;
84}