mod generate;
mod help;
mod import;
mod list;
use abscissa::Callable;
use yubihsm;
use self::{
generate::GenerateCommand, help::HelpCommand, import::ImportCommand, list::ListCommand,
};
pub const DEFAULT_KEY_TYPE: &str = "ed25519";
pub const DEFAULT_DOMAINS: yubihsm::Domain = yubihsm::Domain::DOM1;
pub const DEFAULT_CAPABILITIES: yubihsm::Capability = yubihsm::Capability::ASYMMETRIC_SIGN_EDDSA;
#[derive(Debug, Options)]
pub enum KeysCommand {
#[options(help = "generate an Ed25519 signing key inside the HSM device")]
Generate(GenerateCommand),
#[options(help = "show help for the 'yubihsm keys' subcommand")]
Help(HelpCommand),
#[options(help = "import validator signing key for the 'yubihsm keys' subcommand")]
Import(ImportCommand),
#[options(help = "list all suitable Ed25519 keys in the HSM")]
List(ListCommand),
}
impl KeysCommand {
pub(super) fn config_path(&self) -> Option<&str> {
match self {
KeysCommand::Generate(generate) => generate.config.as_ref().map(|s| s.as_ref()),
KeysCommand::List(list) => list.config.as_ref().map(|s| s.as_ref()),
KeysCommand::Import(import) => import.config.as_ref().map(|s| s.as_ref()),
_ => None,
}
}
}
impl Callable for KeysCommand {
fn call(&self) {
match self {
KeysCommand::Generate(generate) => generate.call(),
KeysCommand::Help(help) => help.call(),
KeysCommand::Import(import) => import.call(),
KeysCommand::List(list) => list.call(),
}
}
}
impl_command!(KeysCommand);