Skip to main content

signstar_yubihsm2/automation/
error.rs

1//! Error handling for automation actions.
2
3use std::fmt::Display;
4
5use crate::automation::command::CommandName;
6
7/// The
8#[derive(Debug)]
9pub struct FileBackedScenarioReturnValueMismatch {
10    pub(crate) file_backed_scenario_command: CommandName,
11    pub(crate) command_return_value: CommandName,
12}
13
14impl Display for FileBackedScenarioReturnValueMismatch {
15    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
16        write!(
17            f,
18            "{} -> {}",
19            self.file_backed_scenario_command, self.command_return_value
20        )
21    }
22}
23
24/// The error that may occur when automating actions against a YubiHSM2 device.
25#[derive(Debug, thiserror::Error)]
26pub enum Error {
27    /// There are mismatches between commands in a file backed scenario and command return values.
28    #[error(
29        "Mismatches between commands in file backed scenarios and the collected return values exist:\n{}",
30        mismatches
31            .iter()
32            .map(ToString::to_string)
33            .collect::<Vec<_>>()
34            .join("\n")
35    )]
36    MismatchingReturnValueForFileBackedScenario {
37        /// Mismatches between
38        mismatches: Vec<FileBackedScenarioReturnValueMismatch>,
39    },
40
41    /// The number of authenticated command chains differ in a scenario and scenario return value.
42    #[error(
43        "The scenario tracks {scenario} authenticated command chains and the scenario return value {scenario_return_value}"
44    )]
45    MismatchingNumberOfAuthenticatedCommandChains {
46        /// The number of authenticated command chains in a scenario.
47        scenario: usize,
48
49        /// The number of authenticated command chains in a scenario return values.
50        scenario_return_value: usize,
51    },
52
53    /// The number of commands in an authenticated command chain differ from those in a list of
54    /// command return values.
55    #[error(
56        "The authenticated command chain tracks {authenticated_command_chain} commands while the list of command return values is {command_return_values}"
57    )]
58    MismatchingNumberOfCommands {
59        /// The number of commands in an authenticated command chain.
60        authenticated_command_chain: usize,
61
62        /// The number of authenticated command chains in a scenario return values.
63        command_return_values: usize,
64    },
65}