mod btc;
mod bytes;
mod ecc;
mod int;
mod ls_cd;
mod password;
mod prime;
mod rsa;
mod secret;
mod test_vectors;
use crate::bin_format::*;
#[allow(unused_imports)]
use anyhow::{bail, ensure, Error};
use clap::Subcommand;
use msecret::*;
use num_bigint::BigUint;
use std::io::Write;
pub use self::rsa::*;
pub use btc::*;
pub use bytes::*;
pub use ecc::*;
pub use int::*;
pub use ls_cd::*;
pub use password::*;
pub use prime::*;
pub use secret::*;
pub use test_vectors::*;
#[derive(Debug, Subcommand)]
pub enum Command {
#[command(alias("list"))]
Ls(CommandLs),
Cd { keypath: String },
#[command(subcommand)]
Secret(CommandSecret),
Bytes(CommandBytes),
#[command(alias("integer"))]
Int(CommandInt),
Prime(CommandPrime),
#[command(subcommand)]
Rsa(CommandRsa),
#[command(alias("ec"), subcommand)]
Ecc(CommandEcc),
#[command(subcommand)]
Btc(CommandBtc),
#[command(subcommand)]
Password(CommandPassword),
TestVectors(CommandTestVectors),
#[command(alias("q"), alias("quit"))]
Exit,
}
impl Command {
pub fn process<T: AsMut<S>, S: ToolState, W: Write>(
&self,
mut tool_state: T,
out: &mut W,
) -> Result<(), Error> {
match self {
Command::Ls(x) => return x.process(tool_state, out),
Command::Cd { keypath } => {
let tool_state = tool_state.as_mut();
tool_state.update_keypath(keypath)?;
let keypath = tool_state.get_keypath()?;
let key_map = tool_state.key_map_mut();
key_map.update(keypath);
}
Command::Secret(x) => return x.process(tool_state, out),
Command::Bytes(x) => return x.process(tool_state, out),
Command::Int(x) => return x.process(tool_state, out),
Command::Prime(x) => return x.process(tool_state, out),
Command::Rsa(x) => return x.process(tool_state, out),
Command::Ecc(x) => return x.process(tool_state, out),
Command::Btc(x) => return x.process(tool_state, out),
Command::Password(x) => return x.process(tool_state, out),
Command::TestVectors(x) => return x.process(tool_state, out),
Command::Exit => {}
}
Ok(())
}
}