diff --git a/rust/pvattest/src/cli.rs b/rust/pvattest/src/cli.rs index e66bfc0f..cd939fa7 100644 --- a/rust/pvattest/src/cli.rs +++ b/rust/pvattest/src/cli.rs @@ -217,12 +217,20 @@ pub enum OutputType { #[derive(Args, Debug)] pub struct CheckOpt { /// Specify the attestation response to check whether the policies are validated. - #[arg(value_name = "IN", value_hint = ValueHint::FilePath,)] - pub input: PathBuf, + #[arg(short, long, value_name = "FILE", value_hint = ValueHint::FilePath,)] + input: Option, + + /// Specify the attestation response to check whether the policies are validated. + #[arg(value_name = "IN", value_hint = ValueHint::FilePath, required_unless_present("input"), conflicts_with("input"))] + input_pos: Option, /// Specify the output file for the check result. - #[arg(value_name = "OUT", value_hint = ValueHint::FilePath,)] - pub output: PathBuf, + #[arg(short, long, value_name = "FILE", value_hint = ValueHint::FilePath,)] + output: Option, + + /// Specify the output file for the check result. + #[arg(value_name = "OUT", value_hint = ValueHint::FilePath, required_unless_present("output"), conflicts_with("output"))] + output_pos: Option, /// Define the output format. #[arg(long, value_enum, default_value_t)] @@ -300,6 +308,30 @@ pub struct CheckOpt { pub firmware_verify_url: Option, } +#[derive(Debug)] +pub struct CheckOptIO<'a> { + pub input: &'a PathBuf, + pub output: &'a PathBuf, +} + +impl<'a> From<&'a CheckOpt> for CheckOptIO<'a> { + fn from(value: &'a CheckOpt) -> Self { + let input = match (&value.input, &value.input_pos) { + (None, Some(i)) => i, + (Some(i), None) => i, + (Some(_), Some(_)) => unreachable!(), + (None, None) => unreachable!(), + }; + let output = match (&value.output, &value.output_pos) { + (None, Some(o)) => o, + (Some(o), None) => o, + (Some(_), Some(_)) => unreachable!(), + (None, None) => unreachable!(), + }; + Self { input, output } + } +} + #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum, Debug)] pub enum HostKeyCheckPolicy { /// Check the host-key used for the attestation request. diff --git a/rust/pvattest/src/cmd/check.rs b/rust/pvattest/src/cmd/check.rs index 5a10b650..dab8327c 100644 --- a/rust/pvattest/src/cmd/check.rs +++ b/rust/pvattest/src/cmd/check.rs @@ -12,7 +12,12 @@ use self::{ secret_store::secret_store_check, secret_store::SecretStoreCheck, }; -use crate::{additional::AttestationResult, cli::CheckOpt, exchange::ExchangeFormatResponse}; +use crate::{ + additional::AttestationResult, + cli::{CheckOpt, CheckOptIO}, + exchange::ExchangeFormatResponse, +}; + use anyhow::Result; use log::{debug, info, warn}; use pv::{ @@ -104,7 +109,8 @@ pub struct CheckResult<'a> { /// Perform the policy checks pub fn check(opt: &CheckOpt) -> Result { - let mut input = open_file(&opt.input)?; + let opt_io = CheckOptIO::from(opt); + let mut input = open_file(opt_io.input)?; let inp = ExchangeFormatResponse::read(&mut input)?; let auth = AttestationRequest::auth_bin(inp.arcb())?; let att_res = AttestationResult::from_exchange(&inp, auth.flags())?; @@ -139,7 +145,7 @@ pub fn check(opt: &CheckOpt) -> Result { }; debug!("res {res:?}"); - let output = create_file(&opt.output)?; + let output = create_file(opt_io.output)?; serde_yaml::to_writer(output, &res)?; match res.successful {