From b00b38d7ddb96f8a03909e0ae490081a43726f3e Mon Sep 17 00:00:00 2001 From: Alexander Ng Date: Tue, 3 Sep 2024 01:07:52 -0700 Subject: [PATCH] chore: remove unused code refactor: remove unused code --- src/commands/upload.rs | 6 +----- src/utils/btreemap.rs | 18 ------------------ src/utils/config.rs | 11 +++++++---- src/utils/settings.rs | 3 --- src/utils/variable.rs | 5 ++--- 5 files changed, 10 insertions(+), 33 deletions(-) diff --git a/src/commands/upload.rs b/src/commands/upload.rs index e61f21a..9c72b87 100644 --- a/src/commands/upload.rs +++ b/src/commands/upload.rs @@ -29,11 +29,7 @@ pub async fn command(args: Args) -> Result<()> { let id = SDK::new_user(&username, &key.public_key()?).await?; println!("UUID: {}", &id); - for k in config.keys.iter_mut() { - if k.fingerprint == key.fingerprint { - k.uuid = Some(id.clone()); - } - } + config.set_uuid(&key.fingerprint, &id)?; config.write()?; diff --git a/src/utils/btreemap.rs b/src/utils/btreemap.rs index 6358555..7feb5be 100644 --- a/src/utils/btreemap.rs +++ b/src/utils/btreemap.rs @@ -7,12 +7,6 @@ pub trait ToBTreeMap { fn to_btreemap(&self) -> Result>; } -pub trait FromBTreeMap { - fn from_btreemap(map: &BTreeMap) -> Result - where - Self: Sized; -} - impl ToBTreeMap for Config { fn to_btreemap(&self) -> Result> { // Convert Config to JSON value @@ -43,18 +37,6 @@ impl ToBTreeMap for Settings { } } -impl FromBTreeMap for Settings { - fn from_btreemap(map: &BTreeMap) -> Result { - // Convert BTreeMap to JSON value - let v: Value = serde_json::to_value(map) - .context("Failed to convert BTreeMap to JSON value")?; - - // Convert JSON value into Settings - serde_json::from_value(v) - .context("Failed to convert JSON value to Settings") - } -} - impl ToBTreeMap for Vec { fn to_btreemap(&self) -> Result> { let mut map = BTreeMap::new(); diff --git a/src/utils/config.rs b/src/utils/config.rs index 810e7f0..abfa4e6 100644 --- a/src/utils/config.rs +++ b/src/utils/config.rs @@ -219,10 +219,13 @@ impl Config { } pub fn set_uuid(&mut self, fingerprint: &str, uuid: &str) -> Result<()> { - let mut key = Self::get_key(self, fingerprint)?.clone(); - self.keys.retain(|k| k.fingerprint != fingerprint); - key.uuid = Some(uuid.to_string()); - self.keys.push(key); + for k in self.keys.iter_mut() { + if k.fingerprint == fingerprint { + k.uuid = Some(uuid.to_string()); + return Ok(()); + } + } + Ok(()) } } diff --git a/src/utils/settings.rs b/src/utils/settings.rs index 5894dca..1ae4ace 100644 --- a/src/utils/settings.rs +++ b/src/utils/settings.rs @@ -28,9 +28,6 @@ impl Settings { pub fn set_keyring_expiry_never(&mut self) { self.keyring_expiry = Some(KeyringExpiry::Never); } - pub fn set_warn_on_short_passwords(&mut self, warn: bool) { - self.warn_on_short_passwords = warn; - } pub fn get_keyring_expiry_days(&self) -> Option { match self.keyring_expiry { Some(KeyringExpiry::Days(d)) => Some(d), diff --git a/src/utils/variable.rs b/src/utils/variable.rs index 301363d..9af17ea 100644 --- a/src/utils/variable.rs +++ b/src/utils/variable.rs @@ -1,6 +1,7 @@ +use super::kvpair::KVPair; use serde::{Deserialize, Serialize}; +use std::{collections::HashMap, fmt::Display}; -use super::kvpair::KVPair; #[derive(Serialize, Deserialize, Clone, Debug)] pub struct EncryptedVariable { pub id: String, @@ -21,8 +22,6 @@ pub trait DeDupe { fn dedupe(&self) -> Self; } -use std::{collections::HashMap, fmt::Display}; - impl DeDupe for Vec { fn dedupe(&self) -> Self { let mut sorted_vec = self.clone();