signstar_yubihsm2/automation/
scenario.rs1#[cfg(feature = "serde")]
4use serde::Deserialize;
5
6use crate::{
7 Credentials,
8 automation::Command,
9 automation::command::{AuthenticatedCommandChain, FileBackedAuthenticatedCommandChain},
10};
11
12#[derive(Debug)]
16pub struct Scenario(Vec<AuthenticatedCommandChain>);
17
18impl AsRef<[AuthenticatedCommandChain]> for Scenario {
19 fn as_ref(&self) -> &[AuthenticatedCommandChain] {
20 self.0.as_slice()
21 }
22}
23
24#[derive(Debug)]
28#[cfg_attr(feature = "serde", derive(Deserialize))]
29pub struct FileBackedScenario(Vec<FileBackedAuthenticatedCommandChain>);
30
31impl AsRef<[FileBackedAuthenticatedCommandChain]> for FileBackedScenario {
32 fn as_ref(&self) -> &[FileBackedAuthenticatedCommandChain] {
33 self.0.as_slice()
34 }
35}
36
37impl TryFrom<&FileBackedScenario> for Scenario {
38 type Error = crate::Error;
39
40 fn try_from(value: &FileBackedScenario) -> Result<Self, Self::Error> {
41 let mut output = Vec::new();
42
43 for authenticated_command_chain in value.0.iter() {
44 let creds = Credentials::try_from(&authenticated_command_chain.auth)?;
45 let commands = {
46 let mut commands = Vec::new();
47 for file_backed_command in authenticated_command_chain.commands.iter() {
48 commands.push(Command::try_from(file_backed_command)?);
49 }
50 commands
51 };
52 output.push(AuthenticatedCommandChain::new(creds, commands));
53 }
54
55 Ok(Self(output))
56 }
57}