From 74870c135e43d5c9543033bd2c6fb484ff80e925 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sun, 3 May 2020 23:57:48 -0400 Subject: maintain folder and uris when editing an entry --- src/bin/rbw/commands.rs | 56 +++++++++++++++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 23 deletions(-) (limited to 'src/bin/rbw/commands.rs') diff --git a/src/bin/rbw/commands.rs b/src/bin/rbw/commands.rs index fa4cc39..b9be09b 100644 --- a/src/bin/rbw/commands.rs +++ b/src/bin/rbw/commands.rs @@ -509,9 +509,12 @@ pub fn add( &access_token, &refresh_token, &name, - &rbw::db::EntryData::Login { username, password }, + &rbw::db::EntryData::Login { + username, + password, + uris, + }, notes.as_deref(), - &uris, folder_id.as_deref(), )? { db.access_token = Some(access_token); @@ -598,9 +601,9 @@ pub fn generate( &rbw::db::EntryData::Login { username, password: Some(password), + uris, }, None, - &uris, folder_id.as_deref(), )? { db.access_token = Some(access_token); @@ -656,12 +659,15 @@ pub fn edit(name: &str, username: Option<&str>) -> anyhow::Result<()> { }) .transpose()?; let mut history = entry.history.clone(); - let (entry_username, entry_password) = match &entry.data { - rbw::db::EntryData::Login { username, password } => { - (username, password) - } - _ => unreachable!(), - }; + let (entry_username, entry_password, entry_uris) = + match &entry.data { + rbw::db::EntryData::Login { + username, + password, + uris, + } => (username, password, uris), + _ => unreachable!(), + }; let new_history_entry = rbw::db::HistoryEntry { last_used_date: format!( "{}", @@ -673,6 +679,7 @@ pub fn edit(name: &str, username: Option<&str>) -> anyhow::Result<()> { let data = rbw::db::EntryData::Login { username: entry_username.clone(), password, + uris: entry_uris.to_vec(), }; (data, notes, history) } @@ -691,6 +698,7 @@ pub fn edit(name: &str, username: Option<&str>) -> anyhow::Result<()> { &entry.name, &data, notes.as_deref(), + entry.folder_id.as_deref(), &history, )? { db.access_token = Some(access_token); @@ -970,20 +978,20 @@ fn decrypt_cipher(entry: &rbw::db::Entry) -> anyhow::Result { .collect::>()?; let data = match &entry.data { - rbw::db::EntryData::Login { username, password } => { - DecryptedData::Login { - username: decrypt_field( - "username", - username.as_deref(), - entry.org_id.as_deref(), - ), - password: decrypt_field( - "password", - password.as_deref(), - entry.org_id.as_deref(), - ), - } - } + rbw::db::EntryData::Login { + username, password, .. + } => DecryptedData::Login { + username: decrypt_field( + "username", + username.as_deref(), + entry.org_id.as_deref(), + ), + password: decrypt_field( + "password", + password.as_deref(), + entry.org_id.as_deref(), + ), + }, rbw::db::EntryData::Card { cardholder_name, number, @@ -1278,12 +1286,14 @@ mod test { id: "irrelevant".to_string(), org_id: None, folder: None, + folder_id: None, name: "this is the encrypted name".to_string(), data: rbw::db::EntryData::Login { username: username.map(|_| { "this is the encrypted username".to_string() }), password: None, + uris: vec![], }, notes: None, history: vec![], -- cgit v1.2.3-54-g00ecf