From 47318142b8183f0d645fb0a7b9e55ae63ceb4dfe Mon Sep 17 00:00:00 2001 From: Awiteb Date: Sat, 11 May 2024 10:33:13 +0300 Subject: [PATCH] chore: Rename `utils::user_password` to `user_secret` --- src/cli/add_command.rs | 3 ++- src/cli/edit_command.rs | 2 +- src/cli/export_command.rs | 2 +- src/cli/import_command.rs | 2 +- src/utils.rs | 18 +++++++++--------- 5 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/cli/add_command.rs b/src/cli/add_command.rs index 709cd1a..28ec52a 100644 --- a/src/cli/add_command.rs +++ b/src/cli/add_command.rs @@ -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()?; diff --git a/src/cli/edit_command.rs b/src/cli/edit_command.rs index 6586e60..e360e65 100644 --- a/src/cli/edit_command.rs +++ b/src/cli/edit_command.rs @@ -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); diff --git a/src/cli/export_command.rs b/src/cli/export_command.rs index d609854..dcebf62 100644 --- a/src/cli/export_command.rs +++ b/src/cli/export_command.rs @@ -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 { diff --git a/src/cli/import_command.rs b/src/cli/import_command.rs index a641a78..6466829 100644 --- a/src/cli/import_command.rs +++ b/src/cli/import_command.rs @@ -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 { diff --git a/src/utils.rs b/src/utils.rs index 71b999d..5577a04 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -45,24 +45,24 @@ pub fn local_project_file(filename: &str) -> LprsResult { 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>, +/// - When failed to get the secret from stdin +pub fn user_secret( + secret: Option>, prompt_message: &str, ) -> LprsResult> { - 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()