Make password prompts more consistent and polite.
This commit is contained in:
parent
68bf9e91f2
commit
bf1ac88e1d
@ -100,12 +100,13 @@ pub fn encrypt<'a, 'b: 'a>(
|
||||
{
|
||||
let mut passwords: Vec<crypto::Password> = Vec::with_capacity(npasswords);
|
||||
for n in 0..npasswords {
|
||||
let nprompt = format!("Enter password {}", n + 1);
|
||||
let nprompt;
|
||||
if let Some(password) = password::prompt_for_new(
|
||||
if npasswords > 1 {
|
||||
nprompt = format!("message (password {})", n + 1);
|
||||
&nprompt
|
||||
} else {
|
||||
"Enter password"
|
||||
"message"
|
||||
},
|
||||
)? {
|
||||
passwords.push(password)
|
||||
|
@ -103,9 +103,7 @@ pub fn generate(
|
||||
|
||||
if command.with_password {
|
||||
builder = builder.set_password(
|
||||
password::prompt_for_new(
|
||||
"Enter password to protect the key",
|
||||
)?);
|
||||
password::prompt_for_new("key")?);
|
||||
}
|
||||
|
||||
if command.output.path().is_none() && command.rev_cert.is_none() {
|
||||
|
@ -48,7 +48,7 @@ pub fn password(
|
||||
} else if let Some(path) = command.new_password_file {
|
||||
Some(std::fs::read(path)?.into())
|
||||
} else {
|
||||
common::password::prompt_for_new("New password")?
|
||||
common::password::prompt_for_new("key")?
|
||||
};
|
||||
|
||||
if let Some(new) = new_password {
|
||||
|
@ -266,9 +266,7 @@ fn subkey_add(
|
||||
if command.with_password {
|
||||
(
|
||||
keys.into_iter().next().unwrap().0,
|
||||
common::password::prompt_for_new(
|
||||
"Please enter password to encrypt the new subkey",
|
||||
)?
|
||||
common::password::prompt_for_new("subkey")?,
|
||||
)
|
||||
} else {
|
||||
keys.into_iter().next().unwrap()
|
||||
|
@ -6,7 +6,7 @@ use rpassword::prompt_password;
|
||||
use sequoia_openpgp as openpgp;
|
||||
|
||||
/// Prompt to repeat a password.
|
||||
const REPEAT_PROMPT: &str = "Repeat password";
|
||||
const REPEAT_PROMPT: &str = "Please repeat the password";
|
||||
|
||||
/// Prompts twice for a new password and returns an optional [`Password`].
|
||||
///
|
||||
@ -21,8 +21,9 @@ const REPEAT_PROMPT: &str = "Repeat password";
|
||||
/// If the passwords differ, an error message is printed and the
|
||||
/// process is repeated.
|
||||
pub fn prompt_for_new(
|
||||
prompt: &str,
|
||||
reason: &str,
|
||||
) -> Result<Option<Password>> {
|
||||
let prompt = format!("Please enter the password to protect the {}", reason);
|
||||
let width = prompt.len().max(REPEAT_PROMPT.len());
|
||||
let p0 = format!("{:>1$}: ", prompt, width);
|
||||
let p1 = format!("{:>1$}: ", REPEAT_PROMPT, width);
|
||||
|
Loading…
Reference in New Issue
Block a user