From 7a32c43713514c02f783d3c8e0835229e7f59a83 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sun, 19 Apr 2020 21:30:52 -0400 Subject: allow selecting entries by id as well --- src/bin/rbw/commands.rs | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) (limited to 'src/bin/rbw/commands.rs') 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::>()?; - 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::>()?; + find_entry_raw(&ciphers, name, username) + } + } } fn find_entry_raw( -- cgit v1.2.3-54-g00ecf