src/graph/extract/mod.rs
//! Graph extractors — source (SCIP / manifests) and binary (ELF) — feeding the
//! one `G = (V, E)` model.
//!
//! Each node/edge an extractor emits carries a [`Provenance`] tag so a consumer
//! (release-doctor blast-radius, modgunn, the viz) knows whether the fact was
//! reconstructed from **source** or from a compiled **binary** — the two graphs
//! coexist in one warehouse and a binary-derived edge is (necessarily) coarser
//! than a source-derived one.
pub mod binary;
/// The warehouse provenance marker for a node/edge reconstructed from a compiled
/// ELF artefact (as opposed to from source). EPIC item 8 calls for exactly this
/// tag so a node/edge "knows whether it came from source or binary".
pub const BINARY_GRAPH_PROVENANCE: &str = "binary_graph";
/// The provenance marker for a node/edge extracted from source (manifests / SCIP
/// / the syn symbol pass). The counterpart of [`BINARY_GRAPH_PROVENANCE`].
pub const SOURCE_GRAPH_PROVENANCE: &str = "source_graph";
/// Which extractor produced a graph node/edge. Persisted as its
/// [`as_str`](Provenance::as_str) form (the `binary_graph` / `source_graph`
/// warehouse markers) so the two graphs can share one `G` yet stay
/// distinguishable.
#[derive(
Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, serde::Serialize, serde::Deserialize,
)]
pub enum Provenance {
/// Reconstructed from source (manifests / SCIP / syn symbol pass).
Source,
/// Reconstructed from a compiled ELF artefact (the binary extractor).
Binary,
}
impl Provenance {
/// The persisted marker string (`"source_graph"` / `"binary_graph"`).
pub fn as_str(self) -> &'static str {
match self {
Provenance::Source => SOURCE_GRAPH_PROVENANCE,
Provenance::Binary => BINARY_GRAPH_PROVENANCE,
}
}
/// Parse the persisted marker (`"binary_graph"` → [`Provenance::Binary`],
/// anything else → [`Provenance::Source`]) — degrades old/blank data safely.
pub fn from_str_lenient(s: &str) -> Self {
if s == BINARY_GRAPH_PROVENANCE {
Provenance::Binary
} else {
Provenance::Source
}
}
}