pedant_types/attestation.rs
1use serde::{Deserialize, Serialize};
2
3use crate::CapabilityProfile;
4
5/// How deeply the source was analyzed, affecting finding accuracy.
6#[derive(Serialize, Deserialize, Clone, Copy, Debug, PartialEq, Eq, Hash)]
7#[serde(rename_all = "snake_case")]
8pub enum AnalysisTier {
9 /// Pattern-based detection on unresolved syntax trees.
10 Syntactic,
11 /// Type-resolved analysis via rust-analyzer.
12 Semantic,
13 /// Full inter-procedural data-flow tracking.
14 DataFlow,
15}
16
17/// How complete capability extraction was for a hashed source set.
18#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Default)]
19pub struct AnalysisCompleteness {
20 /// Number of reachable files whose capabilities were analyzed successfully.
21 pub analyzed_files: usize,
22 /// Number of reachable files that were hashed but skipped for capability analysis.
23 pub skipped_files: usize,
24 /// Relative paths of hashed files that could not be analyzed.
25 #[serde(default, skip_serializing_if = "<[Box<str>]>::is_empty")]
26 pub skipped_paths: Box<[Box<str>]>,
27}
28
29impl AnalysisCompleteness {
30 /// Returns true when capability extraction succeeded for all hashed files.
31 pub fn is_complete(&self) -> bool {
32 self.skipped_files == 0
33 }
34}
35
36/// Signed attestation binding a source hash to its capability profile.
37#[derive(Serialize, Deserialize, Debug, PartialEq, Eq)]
38pub struct AttestationContent {
39 /// Schema version for forward compatibility (e.g., `"0.1.0"`).
40 pub spec_version: Box<str>,
41 /// SHA-256 digest of the concatenated source files.
42 pub source_hash: Box<str>,
43 /// Crate name from `Cargo.toml`.
44 pub crate_name: Box<str>,
45 /// Crate version from `Cargo.toml`.
46 pub crate_version: Box<str>,
47 /// How deeply the source was analyzed.
48 pub analysis_tier: AnalysisTier,
49 /// UTC seconds since Unix epoch.
50 pub timestamp: u64,
51 /// Whether capability analysis covered all hashed files.
52 #[serde(default, skip_serializing_if = "Option::is_none")]
53 pub analysis_completeness: Option<AnalysisCompleteness>,
54 /// Capability findings from the analysis.
55 pub profile: CapabilityProfile,
56}