signstar_yubihsm2/automation/
error.rs1#[cfg(feature = "cli")]
4use std::fmt::Display;
5use std::path::PathBuf;
6
7#[cfg(feature = "cli")]
8use crate::automation::command::CommandName;
9use crate::automation::command::OpaqueData;
10
11#[cfg(feature = "cli")]
16#[derive(Debug)]
17pub struct FileBackedScenarioReturnValueMismatch {
18 pub(crate) file_backed_scenario_command: CommandName,
20
21 pub(crate) command_return_value: CommandName,
23}
24
25#[cfg(feature = "cli")]
26impl Display for FileBackedScenarioReturnValueMismatch {
27 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
28 write!(
29 f,
30 "{} -> {}",
31 self.file_backed_scenario_command, self.command_return_value
32 )
33 }
34}
35
36#[derive(Debug, thiserror::Error)]
38pub enum Error {
39 #[cfg(feature = "cli")]
41 #[error(
42 "Mismatches between commands in file backed scenarios and the collected return values exist:\n{}",
43 mismatches
44 .iter()
45 .map(ToString::to_string)
46 .collect::<Vec<_>>()
47 .join("\n")
48 )]
49 MismatchingReturnValueForFileBackedScenario {
50 mismatches: Vec<FileBackedScenarioReturnValueMismatch>,
52 },
53
54 #[error(
56 "The scenario tracks {scenario} authenticated command chains and the scenario return value {scenario_return_value}"
57 )]
58 MismatchingNumberOfAuthenticatedCommandChains {
59 scenario: usize,
61
62 scenario_return_value: usize,
64 },
65
66 #[error(
69 "The authenticated command chain tracks {authenticated_command_chain} commands while the list of command return values is {command_return_values}"
70 )]
71 MismatchingNumberOfCommands {
72 authenticated_command_chain: usize,
74
75 command_return_values: usize,
77 },
78
79 #[error(
81 "The size of the data for an opaque object ({data_length} bytes) is larger than the maximum allowed value ({} bytes)",
82 OpaqueData::MAX_DATA_SIZE
83 )]
84 OpaqueDataLength {
85 data_length: usize,
87 },
88
89 #[error(
91 "The size of the data file {path} for an opaque object ({data_length} bytes) is larger than the maximum allowed value ({} bytes)",
92 OpaqueData::MAX_DATA_SIZE
93 )]
94 OpaqueDataFileLength {
95 path: PathBuf,
97
98 data_length: usize,
100 },
101
102 #[error("The path used for opaque data is not a file: {path}")]
104 OpaqueDataNotAFile {
105 path: PathBuf,
107 },
108}