Debian Codegraph @

src/cli/key/subkey/export.rs

raw
1 use clap::Args;
2
3 use crate::cli::examples;
4 use examples::Action;
5 use examples::Actions;
6
7 use crate::cli::types::CertDesignators;
8 use crate::cli::types::ClapData;
9 use crate::cli::types::FileOrStdout;
10 use crate::cli::types::KeyDesignators;
11 use crate::cli::types::cert_designator;
12 use crate::cli::types::key_designator;
13
14 pub struct AdditionalDocs {}
15
16 impl key_designator::AdditionalDocs for AdditionalDocs {
17 fn help(_arg: &'static str, _help: &'static str) -> clap::builder::StyledStr {
18 "Export the secret key material for the specified primary key \
19 or subkey".into()
20 }
21 }
22
23 #[derive(Debug, Args)]
24 #[clap(
25 about = "Export secret key material from the secret key store",
26 long_about = "\
27 Export secret key material from the secret key store
28
29 Exports the secret key material. Note that even if secret key \
30 material is available, it may not be exportable. For instance, secret \
31 key material stored on a hardware security module usually cannot be \
32 exported from the device.
33
34 The entire certificate is exported, but only the specified key's \
35 secret key material is exported. An error is returned if the secret \
36 key material for the specified key is not available.
37
38 If you want to export all secret key material associated with a \
39 certificate, use `sq key export`.
40 ",
41 after_help = EXAMPLES,
42 )]
43 pub struct Command {
44 #[command(flatten)]
45 pub cert: CertDesignators<
46 cert_designator::CertUserIDEmailArgs,
47 cert_designator::CertPrefix,
48 cert_designator::OneValue>,
49
50 #[command(flatten)]
51 pub keys: KeyDesignators<
52 key_designator::DefaultOptions,
53 AdditionalDocs>,
54
55 #[clap(
56 default_value_t = FileOrStdout::default(),
57 help = FileOrStdout::HELP_OPTIONAL,
58 long,
59 value_name = FileOrStdout::VALUE_NAME,
60 )]
61 pub output: FileOrStdout,
62 }
63
64 const EXAMPLES: Actions = Actions {
65 actions: &[
66 Action::setup().command(&[
67 "sq", "key", "import", "alice-secret.pgp"
68 ]).build(),
69
70 Action::example().comment("\
71 Export Alice's signing-capable and encryption-capable subkeys, but not \
72 her primary key or her authentication-capable subkey."
73 ).command(&[
74 "sq", "key", "subkey", "export",
75 "--cert=EB28F26E2739A4870ECC47726F0073F60FD0CBF0",
76 "--key=42020B87D51877E5AF8D272124F3955B0B8DECC8",
77 "--key=74DCDEAF17D9B995679EB52BA6E65EA2C8497728",
78 ]).build(),
79 ]
80 };
81 test_examples!(sq_subkey_key_export, EXAMPLES);