Skip to main content

euv_cli/builder/archive/
const.rs

1/// Canonical filename for the deterministic SHA-256 release inventory manifest.
2pub const RELEASE_MANIFEST_NAME: &str = "euv-release.json";
3
4/// Current schema format version of `euv-release.json`.
5pub const RELEASE_MANIFEST_FORMAT: u32 = 1;
6
7/// Default UNIX file permission mode stored in archives for regular files.
8pub const ARCHIVE_DEFAULT_FILE_MODE: u32 = 0o644;
9
10/// Default UNIX file permission mode stored in archives for executable binaries.
11pub const ARCHIVE_EXECUTABLE_FILE_MODE: u32 = 0o755;
12
13/// Default UNIX directory permission mode stored in archives.
14pub const ARCHIVE_DEFAULT_DIR_MODE: u32 = 0o755;
15
16/// Reserved filenames skipped when generating or validating `euv-release.json`.
17pub(crate) const RELEASE_MANIFEST_RESERVED_NAMES: [&str; 6] = [
18    RELEASE_MANIFEST_NAME,
19    "__euv_local_bundle__.json",
20    "_manifest.json",
21    ".empty",
22    ".nojekyll",
23    "active",
24];
25
26/// Required root HTML entry filename checked when generating `euv-release.json`.
27pub(crate) const RELEASE_MANIFEST_INDEX_HTML: &str = "index.html";
28
29/// Disallowed punctuation bytes inside relative paths listed in `euv-release.json`.
30pub(crate) const RELEASE_FORBIDDEN_PATH_BYTES: &[u8] = b"\\:%?#";
31
32/// Dev-only AI Schema v1 marker bytes scanned in release artifacts.
33pub(crate) const AI_SCHEMA_V1_MARKER: &[u8] = b"euv.ai.schema.v1";
34
35/// Dev-only AI Schema v2 marker bytes scanned in release artifacts.
36pub(crate) const AI_SCHEMA_V2_MARKER: &[u8] = b"euv.ai.schema.v2";
37
38/// Archive extension identifying PKZIP output files.
39pub(crate) const ARCHIVE_EXT_ZIP: &str = ".zip";
40
41/// Archive extension identifying gzipped POSIX tar output files.
42pub(crate) const ARCHIVE_EXT_TAR_GZ: &str = ".tar.gz";
43
44/// Short archive extension identifying gzipped POSIX tar output files.
45pub(crate) const ARCHIVE_EXT_TGZ: &str = ".tgz";
46
47/// IEEE 802.3 reversed CRC-32 polynomial used by PNG, ZIP, and GZIP.
48pub(crate) const CRC32_POLY: u32 = 0xEDB8_8320;
49
50/// RFC 1950 Adler-32 prime modulus.
51pub(crate) const ADLER32_MOD: u32 = 65_521;
52
53/// Maximum uncompressed length of a single RFC 1951 stored DEFLATE block.
54pub(crate) const DEFLATE_MAX_STORED_BLOCK: usize = 65_535;
55
56/// Sliding window size in bytes for RFC 1951 LZ77 matching.
57pub(crate) const DEFLATE_WINDOW_SIZE: usize = 32_768;
58
59/// Minimum LZ77 match length defined by RFC 1951.
60pub(crate) const DEFLATE_MIN_MATCH: usize = 3;
61
62/// Maximum LZ77 match length defined by RFC 1951.
63pub(crate) const DEFLATE_MAX_MATCH: usize = 258;
64
65/// Hash table bucket count for LZ77 3-byte prefix indexing.
66pub(crate) const DEFLATE_HASH_BUCKETS: usize = 4_096;
67
68/// Sentinel value marking an empty LZ77 hash bucket.
69pub(crate) const DEFLATE_HASH_EMPTY: usize = usize::MAX;
70
71/// Maximum Huffman code bit length allowed by RFC 1951.
72pub(crate) const DEFLATE_MAX_BITS: usize = 15;
73
74/// End-of-block symbol value in the RFC 1951 literal/length alphabet.
75pub(crate) const DEFLATE_EOB_SYMBOL: usize = 256;
76
77/// Base lengths for RFC 1951 length symbols 257..=285.
78pub(crate) const DEFLATE_LEN_BASE: [u16; 29] = [
79    3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51, 59, 67, 83, 99, 115, 131,
80    163, 195, 227, 258,
81];
82
83/// Extra bit counts for RFC 1951 length symbols 257..=285.
84pub(crate) const DEFLATE_LEN_EXTRA: [u8; 29] = [
85    0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0,
86];
87
88/// Base distances for RFC 1951 distance symbols 0..=29.
89pub(crate) const DEFLATE_DIST_BASE: [u16; 30] = [
90    1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537,
91    2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577,
92];
93
94/// Extra bit counts for RFC 1951 distance symbols 0..=29.
95pub(crate) const DEFLATE_DIST_EXTRA: [u8; 30] = [
96    0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13,
97    13,
98];
99
100/// Permutation order for RFC 1951 dynamic Huffman code-length alphabet symbols.
101pub(crate) const DEFLATE_CLEN_ORDER: [usize; 19] = [
102    16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15,
103];
104
105/// Standard zlib CMF header byte (DEFLATE with 32 KiB sliding window).
106pub(crate) const ZLIB_HEADER_CMF: u8 = 0x78;
107
108/// Standard zlib FLG header byte (default compression, valid modulo-31 check).
109pub(crate) const ZLIB_HEADER_FLG: u8 = 0x9C;
110
111/// RFC 1952 GZIP 10-byte canonical header (DEFLATE, no flags, zero mtime, unknown OS).
112pub(crate) const GZIP_HEADER_BYTES: [u8; 10] =
113    [0x1F, 0x8B, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF];
114
115/// PKZIP Local File Header signature (`PK\x03\x04`).
116pub(crate) const ZIP_LOCAL_HEADER_SIG: u32 = 0x0403_4B50;
117
118/// PKZIP Central Directory File Header signature (`PK\x01\x02`).
119pub(crate) const ZIP_CENTRAL_HEADER_SIG: u32 = 0x0201_4B50;
120
121/// PKZIP End of Central Directory signature (`PK\x05\x06`).
122pub(crate) const ZIP_EOCD_SIG: u32 = 0x0605_4B50;
123
124/// PKZIP version made by (UNIX host + PKZIP 2.0 compatibility).
125pub(crate) const ZIP_VERSION_MADE_BY: u16 = 0x0314;
126
127/// PKZIP version needed to extract (PKZIP 2.0).
128pub(crate) const ZIP_VERSION_NEEDED: u16 = 20;
129
130/// PKZIP general-purpose bit flag enabling UTF-8 filenames (bit 11).
131pub(crate) const ZIP_FLAG_UTF8: u16 = 0x0800;
132
133/// PKZIP compression method 0 (stored / uncompressed).
134pub(crate) const ZIP_METHOD_STORED: u16 = 0;
135
136/// PKZIP compression method 8 (DEFLATE).
137pub(crate) const ZIP_METHOD_DEFLATE: u16 = 8;
138
139/// UNIX regular file type bits shifted into PKZIP external attributes.
140pub(crate) const ZIP_UNIX_REGULAR_FILE: u32 = 0o100_000;
141
142/// POSIX ustar tar block size in bytes.
143pub(crate) const TAR_BLOCK_SIZE: usize = 512;
144
145/// POSIX ustar magic signature bytes (`ustar\0`).
146pub(crate) const TAR_USTAR_MAGIC: &[u8; 6] = b"ustar\0";
147
148/// POSIX ustar version bytes (`00`).
149pub(crate) const TAR_USTAR_VERSION: &[u8; 2] = b"00";
150
151/// Error message when a release version is not numeric `MAJOR.MINOR.PATCH`.
152pub(crate) const ERR_INVALID_SEMVER: &str = "Release version must be a numeric semantic version";
153
154/// Error message when a distribution path is missing or is a symlink.
155pub(crate) const ERR_INVALID_DIST_DIR: &str = "Distribution must be a regular directory";
156
157/// Error message when a symlink is encountered inside a release directory.
158pub(crate) const ERR_SYMLINK_FORBIDDEN: &str = "Symlink is forbidden inside release directory";
159
160/// Error message when an unsafe path is found inside a release directory.
161pub(crate) const ERR_UNSAFE_RELEASE_PATH: &str = "Unsafe release path detected";
162
163/// Error message when a non-regular entry is found inside a release directory.
164pub(crate) const ERR_NOT_REGULAR_FILE: &str = "Entry is not a regular file";
165
166/// Error message when `index.html` is missing or empty during manifest generation.
167pub(crate) const ERR_MISSING_INDEX_HTML: &str = "Missing nonempty index.html";
168
169/// Error message when a release manifest has an unsupported format number.
170pub(crate) const ERR_MANIFEST_FORMAT: &str = "Unexpected euv-release.json format version";
171
172/// Error message when a release manifest version does not match the expected version.
173pub(crate) const ERR_MANIFEST_VERSION: &str = "Release manifest version mismatch";
174
175/// Error message when a required release asset is missing or empty.
176pub(crate) const ERR_MANIFEST_REQUIRED_MISSING: &str = "Missing or empty required release asset";
177
178/// Error message when a file digest does not match `euv-release.json`.
179pub(crate) const ERR_MANIFEST_SHA_MISMATCH: &str = "Release asset SHA-256 mismatch";
180
181/// Error message when a file byte size does not match `euv-release.json`.
182pub(crate) const ERR_MANIFEST_SIZE_MISMATCH: &str = "Release asset byte size mismatch";
183
184/// Error message when dev-only AI schema markers leak into a release binary.
185pub(crate) const ERR_AI_SCHEMA_LEAK: &str =
186    "Dev-only AI schema marker leaked into release artifact";
187
188/// Error message when an inflate stream is truncated or malformed.
189pub(crate) const ERR_DEFLATE_INVALID: &str = "Invalid or truncated DEFLATE stream";
190
191/// Error message when a zlib stream fails header or Adler-32 verification.
192pub(crate) const ERR_ZLIB_INVALID: &str = "Invalid zlib stream or Adler-32 checksum mismatch";
193
194/// Error message when a gzip stream fails header, CRC-32, or ISIZE verification.
195pub(crate) const ERR_GZIP_INVALID: &str = "Invalid gzip stream or CRC-32/ISIZE mismatch";
196
197/// Error message when an existing ZIP archive cannot be parsed.
198pub(crate) const ERR_ZIP_INVALID: &str = "Invalid or unsupported ZIP archive structure";
199
200/// Error message when a tar entry path exceeds POSIX ustar name/prefix limits.
201pub(crate) const ERR_TAR_PATH_TOO_LONG: &str = "Archive entry path exceeds POSIX ustar limit";
202
203/// Error message when an archive extension is unsupported.
204pub(crate) const ERR_UNSUPPORTED_ARCHIVE_EXT: &str =
205    "Unsupported archive extension (expected .zip, .tar.gz, or .tgz)";