1use std::str::FromStr;
4
5use anyhow::Result;
6use clap::{ArgMatches, Args, FromArgMatches, Parser, Subcommand};
7
8use arti_client::{InertTorClient, TorClient, TorClientConfig};
9use tor_keymgr::KeystoreId;
10use tor_rtcompat::Runtime;
11
12#[derive(Debug, Parser)]
14pub(crate) enum RawSubcommands {
15 #[command(subcommand)]
17 KeysRaw(RawSubcommand),
18}
19
20#[derive(Subcommand, Debug, Clone)]
22pub(crate) enum RawSubcommand {
23 RemoveById(RemoveByIdArgs),
25}
26
27#[derive(Debug, Clone, Args)]
29pub(crate) struct RemoveByIdArgs {
30 raw_entry_id: String,
35
36 #[arg(short, long, default_value_t = String::from("arti"))]
39 keystore_id: String,
40}
41
42pub(crate) fn run<R: Runtime>(
44 runtime: R,
45 keys_matches: &ArgMatches,
46 config: &TorClientConfig,
47) -> Result<()> {
48 let subcommand =
49 RawSubcommand::from_arg_matches(keys_matches).expect("Could not parse keys subcommand");
50 let client = TorClient::with_runtime(runtime)
51 .config(config.clone())
52 .create_inert()?;
53
54 match subcommand {
55 RawSubcommand::RemoveById(args) => run_raw_remove(&args, &client),
56 }
57}
58
59fn run_raw_remove(args: &RemoveByIdArgs, client: &InertTorClient) -> Result<()> {
61 let keymgr = client.keymgr()?;
62 let keystore_id = KeystoreId::from_str(&args.keystore_id)?;
63 keymgr.remove_unchecked(&args.raw_entry_id, &keystore_id)?;
64
65 Ok(())
66}