Skip to main content

keyhog_core/
compiled_artifact.rs

1//! Compiled-artifact class model and canonical identity contracts.
2//!
3//! Every compiled artifact class that KeyHog persists or maps (GPU literal set,
4//! Phase-2 GPU DFA catalog, Hyperscan database, detector plan, execution pack,
5//! matcher artifact) belongs to this registered enumeration.
6
7use serde::{Deserialize, Serialize};
8use std::fmt;
9
10/// The complete enumeration of compiled artifact classes used by KeyHog.
11#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
12#[serde(rename_all = "kebab-case")]
13pub enum CompiledArtifactClass {
14    /// GPU literal match tables and kernel parameters.
15    GpuLiteralSet,
16    /// GPU Phase-2 deterministic finite automaton state transition graph.
17    Phase2GpuDfaCatalog,
18    /// Hyperscan / Vectorscan compiled regex database shards.
19    HyperscanDatabase,
20    /// Precompiled detector plan containing regexes and literal indices.
21    DetectorPlan,
22    /// Authenticated self-contained execution pack.
23    ExecutionPack,
24    /// Persistent matcher artifact graph (`.khm`).
25    MatcherArtifact,
26}
27
28impl CompiledArtifactClass {
29    /// List all registered compiled artifact classes.
30    pub const ALL: &'static [CompiledArtifactClass] = &[
31        CompiledArtifactClass::GpuLiteralSet,
32        CompiledArtifactClass::Phase2GpuDfaCatalog,
33        CompiledArtifactClass::HyperscanDatabase,
34        CompiledArtifactClass::DetectorPlan,
35        CompiledArtifactClass::ExecutionPack,
36        CompiledArtifactClass::MatcherArtifact,
37    ];
38
39    /// Operator-facing label for the compiled artifact class.
40    pub const fn label(self) -> &'static str {
41        match self {
42            Self::GpuLiteralSet => "gpu-literal-set",
43            Self::Phase2GpuDfaCatalog => "phase2-gpu-dfa-catalog",
44            Self::HyperscanDatabase => "hyperscan-database",
45            Self::DetectorPlan => "detector-plan",
46            Self::ExecutionPack => "execution-pack",
47            Self::MatcherArtifact => "matcher-artifact",
48        }
49    }
50
51    /// Compile owner / subsystem responsible for producing this artifact.
52    pub const fn compile_owner(self) -> &'static str {
53        match self {
54            Self::GpuLiteralSet => "keyhog-scanner::gpu_literal_artifacts",
55            Self::Phase2GpuDfaCatalog => "keyhog-scanner::engine::phase2_gpu_dfa",
56            Self::HyperscanDatabase => "keyhog-scanner::simd::backend",
57            Self::DetectorPlan => "keyhog-scanner::compiled_scanner",
58            Self::ExecutionPack => "keyhog-scanner::execution_pack",
59            Self::MatcherArtifact => "keyhog-scanner::matcher_artifact_cache",
60        }
61    }
62}
63
64impl fmt::Display for CompiledArtifactClass {
65    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
66        write!(f, "{}", self.label())
67    }
68}
69
70/// Canonical compiled artifact identity binding.
71///
72/// Shared definition of compiled artifact identity across all caching and
73/// execution layers.
74#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
75pub struct CompiledArtifactIdentity {
76    /// The class of compiled artifact.
77    pub artifact_class: CompiledArtifactClass,
78    /// Digest of the running binary executable.
79    pub binary_digest: String,
80    /// Digest of the active detector corpus.
81    pub detector_digest: String,
82    /// Digest of the active resolved configuration.
83    pub config_digest: String,
84    /// Target platform string (`os-arch`).
85    pub platform: String,
86    /// Optional target accelerator / adapter descriptor.
87    pub adapter_identity: Option<String>,
88}