pvattest: Add -i -o option variant for check

Most pvattest subcommands use the command line option -i <input> and -o
<output> to specify file input and output respectively. pvattest check
however only uses positional arguments for <input> and <output>, e.g.

$ pvattest check input.bin output.yaml

This provides an inconsistent user interface within the tool and may
confuse users.

Add the command -i and -o option to the check subcommand to bring it in
line with the rest of the tool.

$ pvattest check -i input.bin -o output.yaml

Reviewed-by: Jan Höppner <hoeppner@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
This commit is contained in:
Steffen Eiden
2026-05-19 17:15:44 +02:00
committed by Jan Höppner
parent d2a6a771a5
commit a50d0485c9
2 changed files with 45 additions and 7 deletions

View File

@@ -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<PathBuf>,
/// 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<PathBuf>,
/// 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<PathBuf>,
/// 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<PathBuf>,
/// Define the output format.
#[arg(long, value_enum, default_value_t)]
@@ -300,6 +308,30 @@ pub struct CheckOpt {
pub firmware_verify_url: Option<String>,
}
#[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.

View File

@@ -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<ExitCode> {
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<ExitCode> {
};
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 {