From 988296d6c9e053d632ee5610ba3432a02776b132 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sun, 19 Apr 2020 05:10:23 -0400 Subject: track password history --- src/api.rs | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'src/api.rs') diff --git a/src/api.rs b/src/api.rs index d5511c5..efceda8 100644 --- a/src/api.rs +++ b/src/api.rs @@ -106,6 +106,8 @@ struct CiphersPutReq { name: String, notes: Option, login: CiphersPutReqLogin, + #[serde(rename = "passwordHistory")] + password_history: Vec, } #[derive(serde::Serialize, Debug)] @@ -114,6 +116,14 @@ struct CiphersPutReqLogin { password: Option, } +#[derive(serde::Serialize, Debug)] +struct CiphersPutReqHistory { + #[serde(rename = "LastUsedDate")] + last_used_date: String, + #[serde(rename = "Password")] + password: String, +} + #[derive(serde::Deserialize, Debug)] struct CiphersRes { #[serde(rename = "FolderId")] @@ -181,16 +191,30 @@ struct SyncResCipher { login: SyncResLogin, #[serde(rename = "Notes")] notes: Option, + #[serde(rename = "PasswordHistory")] + password_history: Option>, } impl SyncResCipher { fn to_entry(&self) -> crate::db::Entry { + let history = if let Some(history) = &self.password_history { + history + .iter() + .map(|entry| crate::db::HistoryEntry { + last_used_date: entry.last_used_date.clone(), + password: entry.password.clone(), + }) + .collect() + } else { + vec![] + }; crate::db::Entry { id: self.id.clone(), name: self.name.clone(), username: self.login.username.clone(), password: self.login.password.clone(), notes: self.notes.clone(), + history, } } } @@ -203,6 +227,14 @@ struct SyncResLogin { password: Option, } +#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)] +struct SyncResPasswordHistory { + #[serde(rename = "LastUsedDate")] + last_used_date: String, + #[serde(rename = "Password")] + password: String, +} + #[derive(Debug)] pub struct Client { base_url: String, @@ -359,6 +391,7 @@ impl Client { username: Option<&str>, password: Option<&str>, notes: Option<&str>, + history: &[crate::db::HistoryEntry], ) -> Result<()> { let req = CiphersPutReq { ty: 1, @@ -368,6 +401,13 @@ impl Client { username: username.map(std::string::ToString::to_string), password: password.map(std::string::ToString::to_string), }, + password_history: history + .iter() + .map(|entry| CiphersPutReqHistory { + last_used_date: entry.last_used_date.clone(), + password: entry.password.clone(), + }) + .collect(), }; let client = reqwest::blocking::Client::new(); let res = client -- cgit v1.2.3-54-g00ecf