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
//! Shared Hyperscan serialized-database cache header contract.
/// Filename prefix of every KeyHog Hyperscan shard cache file (`hs-<sha256>.db`).
/// Single owner shared by the hardening lockdown gate (which strips it to
/// recognise a trusted compiled-pattern cache) and the scanner shard writer
/// (which builds the name), so the two can never disagree.
pub const HYPERSCAN_CACHE_PREFIX: &str = "hs-";
/// Filename suffix of every KeyHog Hyperscan shard cache file. See
/// [`HYPERSCAN_CACHE_PREFIX`].
pub const HYPERSCAN_CACHE_SUFFIX: &str = ".db";
/// Magic bytes at the front of every KeyHog Hyperscan shard cache file.
pub const HYPERSCAN_CACHE_MAGIC: & = b"KHHS";
/// KeyHog-owned cache header version for serialized Hyperscan shard files.
pub const HYPERSCAN_CACHE_VERSION: u32 = 2;
/// Byte length of the KeyHog Hyperscan cache header: magic plus little-endian version.
pub const HYPERSCAN_CACHE_HEADER_LEN: usize = 8;
/// Hard cap for one serialized Hyperscan shard cache file, including the KeyHog header.
///
/// This is a performance-cache bound, not a detector correctness bound. Files above
/// this cap are not loaded or persisted; the scanner compiles from detector patterns
/// instead. The cap is intentionally owned in core so read-side validation and
/// write-side persistence cannot drift.
pub const HYPERSCAN_CACHE_FILE_BYTES: u64 = 128 * 1024 * 1024;
/// Return true when `header` is exactly the current KeyHog Hyperscan cache header.
/// Append the current KeyHog Hyperscan cache header to a serialized-cache buffer.
/// Build the on-disk filename of a KeyHog Hyperscan shard cache file from its
/// content `shard_key`: `hs-<shard_key>.db`. Single owner of the name FORMAT,
/// shared by the scanner shard writer (which persists the file) and the
/// hardening lockdown gate (which recognises/strips it via
/// [`HYPERSCAN_CACHE_PREFIX`]/[`HYPERSCAN_CACHE_SUFFIX`]), so writer and reader
/// can never disagree on the shard filename. Previously the writer re-inlined
/// the `hs-`/`.db` affixes in a `format!`, a latent drift from this owner.