//! Common password-related functionality such as prompting.
use openpgp::crypto::Password;
use openpgp::Result;
use sequoia_openpgp as openpgp;
/// Prompts for passwords.
pub trait Prompt: Send + Sync {
/// Prompts for a password displaying the given prompt.
fn prompt_password(&self, prompt: &str) -> Result<Password>;
/// Prompts once for a PIN to unlock an existing object.
///
/// This function is intended for consuming artifacts. For
/// example, if a key or subkey is locked and must be unlocked, or
/// a message should be decrypted using a PIN.
fn prompt_to_unlock(&self, reason: &str) -> Result<Password> {
let prompt =
format!("Please enter the PIN to unlock {}: ", reason);
let password = self.prompt_password(&prompt)?;
Ok(password)
}
}