Skip to main content

rite_model/params/
verification.rs

1//! Params for the verification actions.
2
3use schemars::JsonSchema;
4use serde::{Deserialize, Serialize};
5
6use crate::types::Vocabulary;
7
8/// Params for `clock_check` action.
9#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonSchema)]
10#[serde(deny_unknown_fields)]
11#[non_exhaustive]
12pub struct ClockCheckParams {
13    /// Message to display before showing the time.
14    #[serde(default)]
15    pub message: Option<String>,
16}
17
18/// Params for `confirm` action.
19#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonSchema)]
20#[serde(deny_unknown_fields)]
21#[non_exhaustive]
22pub struct ConfirmParams {
23    /// Message to display for confirmation.
24    #[serde(default)]
25    pub message: Option<String>,
26}
27
28/// Display format for the `oral_readback` action.
29#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize)]
30#[serde(into = "String", try_from = "String")]
31#[non_exhaustive]
32pub enum ReadbackFormat {
33    /// NATO phonetic alphabet (default). Also written `nato`.
34    #[default]
35    NatoPhonetic,
36    /// Hex pairs, grouped by 4 bytes.
37    Hex,
38    /// Raw value, no transformation.
39    Raw,
40}
41
42crate::types::vocabulary!(ReadbackFormat {
43    NatoPhonetic => "nato_phonetic" | "nato",
44    Hex => "hex",
45    Raw => "raw",
46});
47
48impl From<ReadbackFormat> for String {
49    fn from(format: ReadbackFormat) -> Self {
50        format.as_str().to_string()
51    }
52}
53
54impl TryFrom<String> for ReadbackFormat {
55    type Error = String;
56
57    fn try_from(s: String) -> Result<Self, Self::Error> {
58        Self::from_name(&s).ok_or_else(|| {
59            format!(
60                "unknown readback format '{s}': expected {}",
61                crate::types::either(Self::ALL.iter().map(|format| format.as_str()))
62            )
63        })
64    }
65}
66
67impl JsonSchema for ReadbackFormat {
68    fn schema_name() -> std::borrow::Cow<'static, str> {
69        "ReadbackFormat".into()
70    }
71
72    fn json_schema(_: &mut schemars::SchemaGenerator) -> schemars::Schema {
73        Self::names_schema()
74    }
75}
76
77/// Params for `oral_readback` action.
78#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonSchema)]
79#[serde(deny_unknown_fields)]
80#[non_exhaustive]
81pub struct OralReadbackParams {
82    /// Instruction shown before the readback, as on the other verification
83    /// actions.
84    #[serde(default)]
85    pub message: Option<String>,
86    /// Value to read aloud. Can be a literal string or artifact reference.
87    #[serde(default)]
88    pub value: Option<String>,
89    /// Display format. Defaults to NATO phonetic.
90    #[serde(default)]
91    pub format: Option<ReadbackFormat>,
92    /// Limit number of characters to read (for long values).
93    #[serde(default)]
94    pub characters: Option<u32>,
95}
96
97/// Params for `check_value` action.
98///
99/// Machine-verified comparison of two values. Use this when both values are known
100/// to the system and comparison is deterministic (e.g., hash verification).
101#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
102#[serde(deny_unknown_fields)]
103#[non_exhaustive]
104pub struct CheckValueParams {
105    /// The computed or actual value to verify (required).
106    pub actual: String,
107    /// The expected value to compare against (required).
108    pub expected: String,
109    /// Human-readable description of what is being verified (for transcript/display).
110    #[serde(default)]
111    pub message: Option<String>,
112    /// If true, only record pass/fail result in evidence (no values or lengths).
113    #[serde(default)]
114    pub sensitive: bool,
115}
116
117/// Params for `machine_info` action.
118#[allow(clippy::struct_excessive_bools)]
119#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
120#[serde(deny_unknown_fields)]
121#[non_exhaustive]
122pub struct MachineInfoParams {
123    /// Include hashed machine ID in evidence (default: true).
124    #[serde(default = "default_true")]
125    pub include_machine_id: bool,
126    /// Include CPU model in evidence (default: true).
127    #[serde(default = "default_true")]
128    pub include_cpu: bool,
129    /// Include OS information in evidence (default: true).
130    #[serde(default = "default_true")]
131    pub include_os: bool,
132    /// Include memory protection status in evidence (default: true).
133    #[serde(default = "default_true")]
134    pub include_security_features: bool,
135    /// Custom message to display before capturing machine info.
136    #[serde(default)]
137    pub message: Option<String>,
138}
139
140fn default_true() -> bool {
141    true
142}
143
144impl Default for MachineInfoParams {
145    fn default() -> Self {
146        Self {
147            include_machine_id: true,
148            include_cpu: true,
149            include_os: true,
150            include_security_features: true,
151            message: None,
152        }
153    }
154}