From 9db9908cd3aa97933a543800d69945484a81e62a Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Mon, 20 Apr 2020 00:05:01 -0400 Subject: add folder as an option for list fields --- src/bin/rbw/commands.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'src/bin/rbw/commands.rs') diff --git a/src/bin/rbw/commands.rs b/src/bin/rbw/commands.rs index ee30950..6c9d18c 100644 --- a/src/bin/rbw/commands.rs +++ b/src/bin/rbw/commands.rs @@ -4,6 +4,7 @@ use anyhow::Context as _; #[cfg_attr(test, derive(Eq, PartialEq))] struct DecryptedCipher { id: String, + folder: Option, name: String, username: Option, password: Option, @@ -22,6 +23,7 @@ enum ListField { Name, Id, User, + Folder, } impl std::convert::TryFrom<&str> for ListField { @@ -32,6 +34,7 @@ impl std::convert::TryFrom<&str> for ListField { "name" => Self::Name, "id" => Self::Id, "user" => Self::User, + "folder" => Self::Folder, _ => return Err(anyhow::anyhow!("unknown field {}", s)), }) } @@ -127,6 +130,11 @@ pub fn list(fields: &[&str]) -> anyhow::Result<()> { .as_ref() .map(std::string::ToString::to_string) .unwrap_or_else(|| "".to_string()), + ListField::Folder => cipher + .folder + .as_ref() + .map(std::string::ToString::to_string) + .unwrap_or_else(|| "".to_string()), }) .collect(); println!("{}", values.join("\t")); @@ -610,6 +618,18 @@ fn find_entry_raw( } fn decrypt_cipher(entry: &rbw::db::Entry) -> anyhow::Result { + let folder = entry + .folder + .as_ref() + .map(|folder| crate::actions::decrypt(folder)) + .transpose(); + let folder = match folder { + Ok(folder) => folder, + Err(e) => { + log::warn!("failed to decrypt folder name: {}", e); + None + } + }; let username = entry .username .as_ref() @@ -658,6 +678,7 @@ fn decrypt_cipher(entry: &rbw::db::Entry) -> anyhow::Result { .collect::>()?; Ok(DecryptedCipher { id: entry.id.clone(), + folder, name: crate::actions::decrypt(&entry.name)?, username, password, @@ -780,6 +801,7 @@ mod test { ( rbw::db::Entry { id: "irrelevant".to_string(), + folder: None, name: "this is the encrypted name".to_string(), username: username .map(|_| "this is the encrypted username".to_string()), @@ -789,6 +811,7 @@ mod test { }, DecryptedCipher { id: "irrelevant".to_string(), + folder: None, name: name.to_string(), username: username.map(std::string::ToString::to_string), password: None, -- cgit v1.2.3-54-g00ecf