aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTin Lai <oscar@tinyiu.com>2023-09-21 12:59:57 +1000
committerTin Lai <oscar@tinyiu.com>2023-09-21 12:59:57 +1000
commit13bea3e874df10e825b7b9b90ce734adc1a71d7d (patch)
tree4e21eb06319ea92529b49170914206d532248c38
parentbb1791d14e64ad83fb57116a24eb913a4946afed (diff)
downloadrbw-13bea3e874df10e825b7b9b90ce734adc1a71d7d.tar.gz
rbw-13bea3e874df10e825b7b9b90ce734adc1a71d7d.zip
implements ability to edit notes
Signed-off-by: Tin Lai <oscar@tinyiu.com>
-rw-r--r--src/api.rs7
-rw-r--r--src/bin/rbw/commands.rs32
2 files changed, 35 insertions, 4 deletions
diff --git a/src/api.rs b/src/api.rs
index bee0606..d21d997 100644
--- a/src/api.rs
+++ b/src/api.rs
@@ -1041,7 +1041,12 @@ impl Client {
history: &[crate::db::HistoryEntry],
) -> Result<()> {
let mut req = CiphersPutReq {
- ty: 1,
+ ty: match data {
+ crate::db::EntryData::Login {..} => 1,
+ crate::db::EntryData::SecureNote {..} => 2,
+ crate::db::EntryData::Card {..} => 3,
+ crate::db::EntryData::Identity {..} => 4,
+ },
folder_id: folder_uuid.map(std::string::ToString::to_string),
organization_id: org_id.map(std::string::ToString::to_string),
name: name.to_string(),
diff --git a/src/bin/rbw/commands.rs b/src/bin/rbw/commands.rs
index 4ea3529..aa7f5b9 100644
--- a/src/bin/rbw/commands.rs
+++ b/src/bin/rbw/commands.rs
@@ -671,12 +671,17 @@ impl std::convert::TryFrom<&String> for ListField {
}
}
-const HELP: &str = r#"
+const HELP_PW: &str = r#"
# The first line of this file will be the password, and the remainder of the
# file (after any blank lines after the password) will be stored as a note.
# Lines with leading # will be ignored.
"#;
+const HELP_NOTES: &str = r#"
+# The content of this file will be stored as a note.
+# Lines with leading # will be ignored.
+"#;
+
pub fn config_show() -> anyhow::Result<()> {
let config = rbw::config::Config::load()?;
serde_json::to_writer_pretty(std::io::stdout(), &config)
@@ -939,7 +944,7 @@ pub fn add(
.map(|username| crate::actions::encrypt(username, None))
.transpose()?;
- let contents = rbw::edit::edit("", HELP)?;
+ let contents = rbw::edit::edit("", HELP_PW)?;
let (password, notes) = parse_editor(&contents);
let password = password
@@ -1140,7 +1145,7 @@ pub fn edit(
contents.push_str(&format!("\n{notes}\n"));
}
- let contents = rbw::edit::edit(&contents, HELP)?;
+ let contents = rbw::edit::edit(&contents, HELP_NOTES)?;
let (password, notes) = parse_editor(&contents);
let password = password
@@ -1188,6 +1193,27 @@ pub fn edit(
};
(data, notes, history)
}
+ DecryptedData::SecureNote {} =>
+ {
+ let data = rbw::db::EntryData::SecureNote {};
+
+ let editor_content = match decrypted.notes {
+ Some(notes) => format!("{notes}\n"),
+ None => format!("\n"),
+ };
+ let contents = rbw::edit::edit(&editor_content, HELP_NOTES)?;
+
+ // prepend blank line to be parsed as pw by `parse_editor`
+ let (_, notes) = parse_editor(&format!("\n{contents}\n"));
+
+ let notes = notes
+ .map(|notes| {
+ crate::actions::encrypt(&notes, entry.org_id.as_deref())
+ })
+ .transpose()?;
+
+ (data, notes, entry.history)
+ }
_ => {
return Err(anyhow::anyhow!(
"modifications are only supported for login entries"