arti/subcommands/
raw.rs
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)]
21pub(crate) enum RawSubcommand {
22 RemoveById(RemoveByIdArgs),
24}
25
26#[derive(Debug, Clone, Args)]
28pub(crate) struct RemoveByIdArgs {
29 raw_entry_id: String,
34
35 #[arg(short, long, default_value_t = String::from("arti"))]
38 keystore_id: String,
39}
40
41pub(crate) fn run<R: Runtime>(
43 runtime: R,
44 keys_matches: &ArgMatches,
45 config: &TorClientConfig,
46) -> Result<()> {
47 let subcommand =
48 RawSubcommand::from_arg_matches(keys_matches).expect("Could not parse keys subcommand");
49 let client = TorClient::with_runtime(runtime)
50 .config(config.clone())
51 .create_inert()?;
52
53 match subcommand {
54 RawSubcommand::RemoveById(args) => run_raw_remove(&args, &client),
55 }
56}
57
58fn run_raw_remove(args: &RemoveByIdArgs, client: &InertTorClient) -> Result<()> {
60 let keymgr = client.keymgr()?;
61 let keystore_id = KeystoreId::from_str(&args.keystore_id)?;
62 keymgr.remove_unchecked(&args.raw_entry_id, &keystore_id)?;
63
64 Ok(())
65}