feat: Support TOTP #45
5 changed files with 14 additions and 13 deletions
|
@ -51,7 +51,8 @@ impl LprsCommand for Add {
|
|||
fn run(mut self, mut vault_manager: Vaults) -> LprsResult<()> {
|
||||
if !self.vault_info.is_empty() {
|
||||
self.vault_info.name = self.vault_info.name.trim().to_string();
|
||||
self.vault_info.password = utils::user_password(self.password, "Vault password:")?;
|
||||
self.vault_info.password = utils::user_secret(self.password, "Vault password:")?;
|
||||
self.vault_info.totp_secret = utils::user_secret(self.totp_secret, "TOTP Secret:")?;
|
||||
self.vault_info.custom_fields = self.custom_fields.into_iter().collect();
|
||||
vault_manager.add_vault(self.vault_info);
|
||||
vault_manager.try_export()?;
|
||||
|
|
|
@ -73,7 +73,7 @@ impl LprsCommand for Edit {
|
|||
vault.name = new_name;
|
||||
}
|
||||
if self.password.is_some() {
|
||||
vault.password = utils::user_password(self.password, "New vault password:")?;
|
||||
vault.password = utils::user_secret(self.password, "New vault password:")?;
|
||||
}
|
||||
if let Some(new_username) = self.username {
|
||||
vault.username = Some(new_username);
|
||||
|
|
|
@ -55,7 +55,7 @@ impl LprsCommand for Export {
|
|||
);
|
||||
|
||||
let encryption_key: Option<[u8; 32]> =
|
||||
utils::user_password(self.encryption_password, "Encryption Password:")?
|
||||
utils::user_secret(self.encryption_password, "Encryption Password:")?
|
||||
.map(|p| sha2::Sha256::digest(p).into());
|
||||
|
||||
let exported_data = match self.format {
|
||||
|
|
|
@ -60,7 +60,7 @@ impl LprsCommand for Import {
|
|||
);
|
||||
|
||||
let decryption_key: Option<[u8; 32]> =
|
||||
utils::user_password(self.decryption_password, "Decryption password:")?
|
||||
utils::user_secret(self.decryption_password, "Decryption password:")?
|
||||
.map(|p| sha2::Sha256::digest(p).into());
|
||||
|
||||
let imported_passwords_len = match self.format {
|
||||
|
|
18
src/utils.rs
18
src/utils.rs
|
@ -45,24 +45,24 @@ pub fn local_project_file(filename: &str) -> LprsResult<PathBuf> {
|
|||
Ok(local_dir.join(filename))
|
||||
}
|
||||
|
||||
/// Returns the user password if any
|
||||
/// Returns the user secret if any
|
||||
///
|
||||
/// - If the `password` is `None` will return `None`
|
||||
/// - If the `password` is `Some(None)` will ask the user for a password in the
|
||||
/// - If the `secret` is `None` will return `None`
|
||||
/// - If the `secret` is `Some(None)` will ask the user for a secret in the
|
||||
/// stdin and return it
|
||||
/// - If the `password` is `Some(Some(password))` will return `Some(password)`
|
||||
/// - If the `secret` is `Some(Some(secret))` will return `Some(secret)`
|
||||
///
|
||||
/// ## Errors
|
||||
/// - When failed to get the password from stdin
|
||||
pub fn user_password(
|
||||
password: Option<Option<String>>,
|
||||
/// - When failed to get the secret from stdin
|
||||
pub fn user_secret(
|
||||
secret: Option<Option<String>>,
|
||||
prompt_message: &str,
|
||||
) -> LprsResult<Option<String>> {
|
||||
Ok(match password {
|
||||
Ok(match secret {
|
||||
None => None,
|
||||
Some(Some(p)) => Some(p),
|
||||
Some(None) => {
|
||||
log::debug!("User didn't provide a password, prompting it");
|
||||
log::debug!("User didn't provide a secret, prompting it");
|
||||
Some(
|
||||
Password::new(prompt_message)
|
||||
.without_confirmation()
|
||||
|
|
Loading…
Reference in a new issue