use abscissa::Callable;
use std::{
thread,
time::{Duration, Instant},
};
use yubihsm;
const TEST_MESSAGE: &[u8; 128] = &[0u8; 128];
#[derive(Debug, Default, Options)]
pub struct TestCommand {
#[options(short = "c", long = "config")]
pub config: Option<String>,
#[options(short = "v", long = "verbose")]
pub verbose: bool,
#[options(free)]
key_id: u16,
}
impl Callable for TestCommand {
fn call(&self) {
let mut hsm = yubihsm::get_hsm_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 {
let duration = Instant::now().duration_since(started_at);
status_ok!(
"Success",
"signed message using key ID #{} in {} ms",
self.key_id,
duration.as_secs() * 1000 + u64::from(duration.subsec_millis())
);
}
}
}
}