use crate::prelude::*;
use abscissa_core::Command;
use clap::Parser;
use std::{
path::PathBuf,
process, thread,
time::{Duration, Instant},
};
const TEST_MESSAGE: &[u8; 128] = &[0u8; 128];
#[derive(Command, Debug, Default, Parser)]
pub struct TestCommand {
#[clap(short = 'c', long = "config")]
pub config: Option<PathBuf>,
#[clap(short = 'v', long = "verbose")]
pub verbose: bool,
key_id: u16,
}
impl Runnable for TestCommand {
fn run(&self) {
if self.key_id == 0 {
status_err!("no key ID given");
process::exit(1);
}
let hsm = crate::yubihsm::client();
loop {
let started_at = Instant::now();
if let Err(e) = hsm.sign_ed25519(self.key_id, TEST_MESSAGE.as_ref()) {
status_err!("signature operation failed: {}", e);
thread::sleep(Duration::from_millis(250));
} else {
status_ok!(
"Success",
"signed message using key ID #{} in {} ms",
self.key_id,
started_at.elapsed().as_millis()
);
}
}
}
}