aboutsummaryrefslogtreecommitdiffstats
path: root/src/bin/rbw/commands.rs
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2020-04-19 21:30:52 -0400
committerJesse Luehrs <doy@tozt.net>2020-04-19 21:30:52 -0400
commit7a32c43713514c02f783d3c8e0835229e7f59a83 (patch)
tree938779384d21d1c5a3874a55e12288e6e5669b66 /src/bin/rbw/commands.rs
parentf949f04a3995e24b8a05a2323426eb69cdb1b922 (diff)
downloadrbw-7a32c43713514c02f783d3c8e0835229e7f59a83.tar.gz
rbw-7a32c43713514c02f783d3c8e0835229e7f59a83.zip
allow selecting entries by id as well
Diffstat (limited to 'src/bin/rbw/commands.rs')
-rw-r--r--src/bin/rbw/commands.rs30
1 files changed, 21 insertions, 9 deletions
diff --git a/src/bin/rbw/commands.rs b/src/bin/rbw/commands.rs
index ff267eb..317d62b 100644
--- a/src/bin/rbw/commands.rs
+++ b/src/bin/rbw/commands.rs
@@ -436,15 +436,27 @@ fn find_entry(
name: &str,
username: Option<&str>,
) -> anyhow::Result<(rbw::db::Entry, DecryptedCipher)> {
- let ciphers: Vec<(rbw::db::Entry, DecryptedCipher)> = db
- .entries
- .iter()
- .cloned()
- .map(|entry| {
- decrypt_cipher(&entry).map(|decrypted| (entry, decrypted))
- })
- .collect::<anyhow::Result<_>>()?;
- find_entry_raw(&ciphers, name, username)
+ match uuid::Uuid::parse_str(name) {
+ Ok(_) => {
+ for cipher in &db.entries {
+ if name == cipher.id {
+ return Ok((cipher.clone(), decrypt_cipher(&cipher)?));
+ }
+ }
+ Err(anyhow::anyhow!("no entry found"))
+ }
+ Err(_) => {
+ let ciphers: Vec<(rbw::db::Entry, DecryptedCipher)> = db
+ .entries
+ .iter()
+ .cloned()
+ .map(|entry| {
+ decrypt_cipher(&entry).map(|decrypted| (entry, decrypted))
+ })
+ .collect::<anyhow::Result<_>>()?;
+ find_entry_raw(&ciphers, name, username)
+ }
+ }
}
fn find_entry_raw(