| 1 |
use std::path::PathBuf; |
| 2 |
|
| 3 |
use clap::Args; |
| 4 |
|
| 5 |
use crate::cli::examples; |
| 6 |
use examples::Action; |
| 7 |
use examples::Actions; |
| 8 |
|
| 9 |
use crate::cli::types::CertDesignators; |
| 10 |
use crate::cli::types::ClapData; |
| 11 |
use crate::cli::types::FileOrStdout; |
| 12 |
use crate::cli::types::KeyDesignators; |
| 13 |
use crate::cli::types::cert_designator; |
| 14 |
use crate::cli::types::key_designator; |
| 15 |
|
| 16 |
pub struct CertAdditionalDocs {} |
| 17 |
|
| 18 |
impl cert_designator::AdditionalDocs for CertAdditionalDocs { |
| 19 |
fn help(arg: &'static str, help: &'static str) -> clap::builder::StyledStr { |
| 20 |
match arg { |
| 21 |
"file" => |
| 22 |
"Change the password for the secret key material of the \ |
| 23 |
specified (sub)keys from the key read from PATH" |
| 24 |
.into(), |
| 25 |
_ => { |
| 26 |
debug_assert!(help.starts_with("Use certificates")); |
| 27 |
help.replace("Use certificates", |
| 28 |
"Change the password for the secret key material \ |
| 29 |
of the specified (sub)keys from the key") |
| 30 |
.into() |
| 31 |
}, |
| 32 |
} |
| 33 |
} |
| 34 |
} |
| 35 |
|
| 36 |
pub struct KeyAdditionalDocs {} |
| 37 |
|
| 38 |
impl key_designator::AdditionalDocs for KeyAdditionalDocs { |
| 39 |
fn help(_arg: &'static str, _help: &'static str) |
| 40 |
-> clap::builder::StyledStr |
| 41 |
{ |
| 42 |
"Change the password protecting the specified key's secret key \ |
| 43 |
material".into() |
| 44 |
} |
| 45 |
} |
| 46 |
|
| 47 |
#[derive(Debug, Args)] |
| 48 |
#[clap( |
| 49 |
name = "password", |
| 50 |
about = "Change the password protecting secret key material", |
| 51 |
long_about = "\ |
| 52 |
Change the password protecting secret key material |
| 53 |
|
| 54 |
Secret key material can be protected by a password. This subcommand \ |
| 55 |
changes or clears the password of one or more keys. |
| 56 |
|
| 57 |
To strip the password either use `--clear` or supply a zero-length \ |
| 58 |
password when prompted for the new password. |
| 59 |
|
| 60 |
If a key is password protected, and the correct password was not \ |
| 61 |
supplied using the `--password-file` argument, the user is \ |
| 62 |
prompted for the password. Likewise, if the new password isn't \ |
| 63 |
provided, the user is prompted. |
| 64 |
", |
| 65 |
after_help = EXAMPLES, |
| 66 |
)] |
| 67 |
pub struct Command { |
| 68 |
#[command(flatten)] |
| 69 |
pub cert: CertDesignators< |
| 70 |
cert_designator::CertUserIDEmailFileArgs, |
| 71 |
cert_designator::CertPrefix, |
| 72 |
cert_designator::OneValueAndFileRequiresOutput, |
| 73 |
CertAdditionalDocs>, |
| 74 |
|
| 75 |
#[command(flatten)] |
| 76 |
pub keys: KeyDesignators< |
| 77 |
key_designator::DefaultOptions, |
| 78 |
KeyAdditionalDocs>, |
| 79 |
|
| 80 |
#[clap( |
| 81 |
long, |
| 82 |
value_name = "PASSWORD_FILE", |
| 83 |
help = "\ |
| 84 |
File containing password to encrypt the secret key material", |
| 85 |
long_help = "\ |
| 86 |
File containing password to encrypt the secret key material |
| 87 |
|
| 88 |
Note that the entire key file will be used as the password including \ |
| 89 |
any surrounding whitespace like a trailing newline." |
| 90 |
)] |
| 91 |
pub new_password_file: Option<PathBuf>, |
| 92 |
#[clap( |
| 93 |
long, |
| 94 |
help = "Clear the password protecting the secret key material", |
| 95 |
)] |
| 96 |
pub clear_password: bool, |
| 97 |
|
| 98 |
#[clap( |
| 99 |
help = FileOrStdout::HELP_OPTIONAL, |
| 100 |
long, |
| 101 |
value_name = FileOrStdout::VALUE_NAME, |
| 102 |
conflicts_with = "cert", |
| 103 |
)] |
| 104 |
pub output: Option<FileOrStdout>, |
| 105 |
} |
| 106 |
|
| 107 |
const EXAMPLES: Actions = Actions { |
| 108 |
actions: &[ |
| 109 |
Action::setup().command(&[ |
| 110 |
"sq", "key", "import", "alice-secret.pgp" |
| 111 |
]).build(), |
| 112 |
|
| 113 |
Action::example().comment("\ |
| 114 |
Change the password for Alice's signing key to the password in the \ |
| 115 |
specified file." |
| 116 |
).command(&[ |
| 117 |
"sq", "key", "subkey", "password", |
| 118 |
"--new-password-file=password-file.txt", |
| 119 |
"--cert=EB28F26E2739A4870ECC47726F0073F60FD0CBF0", |
| 120 |
"--key=42020B87D51877E5AF8D272124F3955B0B8DECC8", |
| 121 |
]).build(), |
| 122 |
|
| 123 |
Action::example().comment("\ |
| 124 |
Clear the password protection for Alice's signing key." |
| 125 |
).command(&[ |
| 126 |
"sq", "key", "subkey", "password", |
| 127 |
"--password-file=password-file.txt", |
| 128 |
"--clear-password", |
| 129 |
"--cert=EB28F26E2739A4870ECC47726F0073F60FD0CBF0", |
| 130 |
"--key=42020B87D51877E5AF8D272124F3955B0B8DECC8", |
| 131 |
]).build(), |
| 132 |
] |
| 133 |
}; |
| 134 |
test_examples!(sq_key_subkey_password, EXAMPLES); |