| 1 |
//! Command-line parser for `sq key password`. |
| 2 |
|
| 3 |
use std::path::PathBuf; |
| 4 |
|
| 5 |
use clap::Args; |
| 6 |
|
| 7 |
use crate::cli::types::*; |
| 8 |
use crate::cli::examples::*; |
| 9 |
use crate::cli::types::cert_designator::*; |
| 10 |
|
| 11 |
#[derive(Debug, Args)] |
| 12 |
#[clap( |
| 13 |
name = "password", |
| 14 |
about = "Change the password protecting secret key material", |
| 15 |
long_about = "\ |
| 16 |
Change the password protecting secret key material |
| 17 |
|
| 18 |
Secret key material can be protected by a password. This subcommand \ |
| 19 |
changes or clears the password. |
| 20 |
|
| 21 |
To strip the password either use `--clear` or supply a zero-length \ |
| 22 |
password when prompted for the new password. |
| 23 |
|
| 24 |
If a key is password protected, and the correct password was not \ |
| 25 |
supplied using the `--password-file` argument, the user is \ |
| 26 |
prompted for the password. Likewise, if the new password isn't \ |
| 27 |
provided, the user is prompted. |
| 28 |
", |
| 29 |
after_help = EXAMPLES, |
| 30 |
)] |
| 31 |
pub struct Command { |
| 32 |
#[command(flatten)] |
| 33 |
pub cert: CertDesignators<CertUserIDEmailFileArgs, |
| 34 |
CertPrefix, |
| 35 |
OneValueAndFileRequiresOutput, |
| 36 |
KeyPasswordDoc>, |
| 37 |
|
| 38 |
#[clap( |
| 39 |
long = "new-password-file", |
| 40 |
value_name = "PASSWORD_FILE", |
| 41 |
help = "\ |
| 42 |
File containing password to encrypt the secret key material", |
| 43 |
long_help = "\ |
| 44 |
File containing password to encrypt the secret key material |
| 45 |
|
| 46 |
Note that the entire key file will be used as the password including \ |
| 47 |
any surrounding whitespace like a trailing newline." |
| 48 |
)] |
| 49 |
pub new_password_file: Option<PathBuf>, |
| 50 |
#[clap( |
| 51 |
long, |
| 52 |
help = "Clear the password protecting the secret key material", |
| 53 |
)] |
| 54 |
pub clear_password: bool, |
| 55 |
|
| 56 |
#[clap( |
| 57 |
help = FileOrStdout::HELP_OPTIONAL, |
| 58 |
long, |
| 59 |
value_name = FileOrStdout::VALUE_NAME, |
| 60 |
)] |
| 61 |
pub output: Option<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 |
Change the password for all of Alice's keys to the password in the \ |
| 72 |
specified file." |
| 73 |
).command(&[ |
| 74 |
"sq", "key", "password", |
| 75 |
"--new-password-file", "password-file.txt", |
| 76 |
"--cert", "EB28F26E2739A4870ECC47726F0073F60FD0CBF0" |
| 77 |
]).build(), |
| 78 |
|
| 79 |
Action::example().comment("\ |
| 80 |
Clear the password protection for all of Alice's keys." |
| 81 |
).command(&[ |
| 82 |
"sq", "key", "password", |
| 83 |
"--password-file", "password-file.txt", |
| 84 |
"--clear-password", |
| 85 |
"--cert", "EB28F26E2739A4870ECC47726F0073F60FD0CBF0" |
| 86 |
]).build(), |
| 87 |
] |
| 88 |
}; |
| 89 |
test_examples!(sq_key_password, EXAMPLES); |
| 90 |
|
| 91 |
/// Documentation for the cert designators for the key password. |
| 92 |
pub struct KeyPasswordDoc {} |
| 93 |
|
| 94 |
impl AdditionalDocs for KeyPasswordDoc { |
| 95 |
fn help(arg: &'static str, help: &'static str) -> clap::builder::StyledStr { |
| 96 |
match arg { |
| 97 |
"file" => |
| 98 |
"Change the password for the secret key material from the key \ |
| 99 |
read from PATH" |
| 100 |
.into(), |
| 101 |
_ => { |
| 102 |
debug_assert!(help.starts_with("Use certificates")); |
| 103 |
help.replace("Use certificates", |
| 104 |
"Change the password for the secret key material \ |
| 105 |
from the key") |
| 106 |
}, |
| 107 |
}.into() |
| 108 |
} |
| 109 |
} |