sequoia_cryptoki/password.rs
1//! Common password-related functionality such as prompting.
2
3use openpgp::crypto::Password;
4use openpgp::Result;
5use sequoia_openpgp as openpgp;
6
7/// Prompts for passwords.
8pub trait Prompt: Send + Sync {
9 /// Prompts for a password displaying the given prompt.
10 fn prompt_password(&self, prompt: &str) -> Result<Password>;
11
12 /// Prompts once for a PIN to unlock an existing object.
13 ///
14 /// This function is intended for consuming artifacts. For
15 /// example, if a key or subkey is locked and must be unlocked, or
16 /// a message should be decrypted using a PIN.
17 fn prompt_to_unlock(&self, reason: &str) -> Result<Password> {
18 let prompt =
19 format!("Please enter the PIN to unlock {}: ", reason);
20 let password = self.prompt_password(&prompt)?;
21 Ok(password)
22 }
23}