From f85aedc29a5e2e19d5cc4fc995ccc8631f084f0b Mon Sep 17 00:00:00 2001 From: Ondrej Prazak Date: Thu, 11 Jan 2024 09:23:18 +0100 Subject: [PATCH] add minor improvements for entry tags --- aries/aries_vcx_core/src/wallet2/entry_tag.rs | 55 ++----------------- .../src/wallet2/indy_wallet/mod.rs | 52 +++++++++++++++++- aries/misc/test_utils/src/devsetup.rs | 3 +- 3 files changed, 57 insertions(+), 53 deletions(-) diff --git a/aries/aries_vcx_core/src/wallet2/entry_tag.rs b/aries/aries_vcx_core/src/wallet2/entry_tag.rs index 9cc3974b52..df0682daf4 100644 --- a/aries/aries_vcx_core/src/wallet2/entry_tag.rs +++ b/aries/aries_vcx_core/src/wallet2/entry_tag.rs @@ -1,40 +1,21 @@ -use std::collections::HashMap; - use serde::{Deserialize, Serialize}; -#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] +#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq, PartialOrd, Ord)] pub enum EntryTag { Encrypted(String, String), Plaintext(String, String), } -#[cfg(feature = "vdrtools_wallet")] -impl From for (String, String) { - fn from(value: EntryTag) -> Self { - match value { - EntryTag::Encrypted(key, val) => (key, val), - EntryTag::Plaintext(key, val) => (format!("~{}", key), val), - } - } -} - -#[cfg(feature = "vdrtools_wallet")] -impl From<(String, String)> for EntryTag { - fn from(value: (String, String)) -> Self { - if value.0.starts_with('~') { - EntryTag::Plaintext(value.0.trim_start_matches('~').into(), value.1) - } else { - EntryTag::Encrypted(value.0, value.1) - } - } -} - #[derive(Debug, Default, Clone, PartialEq)] pub struct EntryTags { inner: Vec, } impl EntryTags { + pub fn new(inner: Vec) -> Self { + Self { inner } + } + pub fn add(&mut self, tag: EntryTag) { self.inner.push(tag) } @@ -79,29 +60,3 @@ impl From for Vec { value.inner } } - -#[cfg(feature = "vdrtools_wallet")] -impl From for HashMap { - fn from(value: EntryTags) -> Self { - let tags: Vec = value.into(); - tags.into_iter().fold(Self::new(), |mut memo, item| { - let (key, value) = item.into(); - - memo.insert(key, value); - memo - }) - } -} - -#[cfg(feature = "vdrtools_wallet")] -impl From> for EntryTags { - fn from(value: HashMap) -> Self { - Self { - inner: value - .into_iter() - .map(|(key, value)| (key, value)) - .map(From::from) - .collect(), - } - } -} diff --git a/aries/aries_vcx_core/src/wallet2/indy_wallet/mod.rs b/aries/aries_vcx_core/src/wallet2/indy_wallet/mod.rs index 9de24a08d4..d0b8c6d324 100644 --- a/aries/aries_vcx_core/src/wallet2/indy_wallet/mod.rs +++ b/aries/aries_vcx_core/src/wallet2/indy_wallet/mod.rs @@ -1,4 +1,9 @@ -use super::BaseWallet2; +use std::collections::HashMap; + +use super::{ + entry_tag::{EntryTag, EntryTags}, + BaseWallet2, +}; use crate::wallet::indy::IndySdkWallet; pub mod indy_did_wallet; @@ -10,3 +15,48 @@ const WALLET_OPTIONS: &str = const SEARCH_OPTIONS: &str = r#"{"retrieveType": true, "retrieveValue": true, "retrieveTags": true, "retrieveRecords": true}"#; impl BaseWallet2 for IndySdkWallet {} + +impl From for (String, String) { + fn from(value: EntryTag) -> Self { + match value { + EntryTag::Encrypted(key, val) => (key, val), + EntryTag::Plaintext(key, val) => (format!("~{}", key), val), + } + } +} + +impl From<(String, String)> for EntryTag { + fn from(value: (String, String)) -> Self { + if value.0.starts_with('~') { + EntryTag::Plaintext(value.0.trim_start_matches('~').into(), value.1) + } else { + EntryTag::Encrypted(value.0, value.1) + } + } +} + +impl From for HashMap { + fn from(value: EntryTags) -> Self { + let tags: Vec = value.into(); + tags.into_iter().fold(Self::new(), |mut memo, item| { + let (key, value) = item.into(); + + memo.insert(key, value); + memo + }) + } +} + +impl From> for EntryTags { + fn from(value: HashMap) -> Self { + let mut items: Vec = value + .into_iter() + .map(|(key, value)| (key, value)) + .map(From::from) + .collect(); + + items.sort(); + + Self::new(items) + } +} diff --git a/aries/misc/test_utils/src/devsetup.rs b/aries/misc/test_utils/src/devsetup.rs index 36372f60d9..967be10170 100644 --- a/aries/misc/test_utils/src/devsetup.rs +++ b/aries/misc/test_utils/src/devsetup.rs @@ -184,8 +184,7 @@ pub async fn dev_build_featured_indy_ledger( }; } -#[allow(unreachable_code)] -#[allow(unused_variables)] +#[allow(clippy::needless_return)] pub async fn dev_build_featured_anoncreds() -> impl BaseAnonCreds { #[cfg(feature = "credx")] {