Debian Codegraph @

src/cli/key/export.rs

raw
1 //! Command-line parser for `sq key list`.
2
3 use clap::Args;
4
5 use crate::cli::examples::*;
6 use crate::cli::types::*;
7 use crate::cli::types::cert_designator::*;
8
9 #[derive(Debug, Args)]
10 #[clap(
11 about = "Export keys from the key store",
12 long_about = "\
13 Export keys from the key store
14
15 Exports the secret key material associated with a certificate. Note \
16 that even if secret key material is available, it may not be \
17 exportable. For instance, secret key material stored on a hardware \
18 security module usually cannot be exported from the device.
19
20 Iterate over all of the specified certificates and export \
21 any keys (primary key and subkeys) with secret key material. \
22 An error is returned if any specified certificate does not \
23 contain any secret key material.
24
25 If you only want to export a particular key and not all keys associate \
26 with a certificate, use `sq key subkey export`.
27 ",
28 after_help = EXAMPLES,
29 )]
30 pub struct Command {
31 #[command(flatten)]
32 pub certs: CertDesignators<CertUserIDEmailDomainGrepArgs,
33 CertPrefix,
34 NoOptions,
35 ExportKeyDoc>,
36
37 #[clap(
38 default_value_t = FileOrStdout::default(),
39 help = FileOrStdout::HELP_OPTIONAL,
40 long,
41 value_name = FileOrStdout::VALUE_NAME,
42 )]
43 pub output: FileOrStdout,
44 }
45
46 const EXAMPLES: Actions = Actions {
47 actions: &[
48 Action::setup().command(&[
49 "sq", "key", "import", "alice-secret.pgp",
50 ]).build(),
51
52 Action::setup().command(&[
53 "sq", "pki", "link", "add",
54 "--cert=EB28F26E2739A4870ECC47726F0073F60FD0CBF0",
55 "--userid=Alice <[email protected]>",
56 ]).build(),
57
58 Action::example().comment("\
59 Export Alice's certificate with all available secret key material."
60 ).command(&[
61 "sq", "key", "export",
62 "--cert", "EB28F26E2739A4870ECC47726F0073F60FD0CBF0",
63 ]).build(),
64
65 Action::example().comment("\
66 Export Alice's certificate with all available secret key material \
67 identified by email address."
68 ).command(&[
69 "sq", "key", "export",
70 "--cert-email", "[email protected]",
71 ]).build(),
72 ]
73 };
74 test_examples!(sq_key_export, EXAMPLES);
75
76 /// Documentation for the cert designators for the key export.
77 pub struct ExportKeyDoc {}
78
79 impl AdditionalDocs for ExportKeyDoc {
80 fn help(_arg: &'static str, help: &'static str) -> clap::builder::StyledStr {
81 debug_assert!(help.starts_with("Use certificates"));
82 help.replace("Use certificates", "Export keys").into()
83 }
84 }