diff --git a/aries/aries_vcx_core/src/anoncreds/credx_anoncreds.rs b/aries/aries_vcx_core/src/anoncreds/credx_anoncreds.rs index 40887dda0a..c844a6f41b 100644 --- a/aries/aries_vcx_core/src/anoncreds/credx_anoncreds.rs +++ b/aries/aries_vcx_core/src/anoncreds/credx_anoncreds.rs @@ -31,7 +31,7 @@ use crate::{ }, wallet::{ base_wallet::{record::Record, search_filter::SearchFilter, BaseWallet, RecordWallet}, - entry_tag::EntryTags, + entry_tags::EntryTags, }, }; diff --git a/aries/aries_vcx_core/src/wallet/agency_client_wallet.rs b/aries/aries_vcx_core/src/wallet/agency_client_wallet.rs index 18bd47ffb7..3b77193c23 100644 --- a/aries/aries_vcx_core/src/wallet/agency_client_wallet.rs +++ b/aries/aries_vcx_core/src/wallet/agency_client_wallet.rs @@ -16,7 +16,7 @@ use super::{ }; use crate::{ errors::error::{AriesVcxCoreError, AriesVcxCoreErrorKind, VcxCoreResult}, - wallet::entry_tag::EntryTags, + wallet::entry_tags::EntryTags, }; #[derive(Debug)] diff --git a/aries/aries_vcx_core/src/wallet/base_wallet/mod.rs b/aries/aries_vcx_core/src/wallet/base_wallet/mod.rs index 1b106c6421..b3b7ba28a0 100644 --- a/aries/aries_vcx_core/src/wallet/base_wallet/mod.rs +++ b/aries/aries_vcx_core/src/wallet/base_wallet/mod.rs @@ -1,7 +1,7 @@ use async_trait::async_trait; use public_key::Key; -use super::entry_tag::EntryTags; +use super::entry_tags::EntryTags; use crate::{ errors::error::VcxCoreResult, wallet::{ @@ -82,7 +82,7 @@ mod tests { errors::error::AriesVcxCoreErrorKind, wallet::{ base_wallet::{DidWallet, Record, RecordWallet}, - entry_tag::{EntryTag, EntryTags}, + entry_tags::EntryTags, }, }; @@ -264,7 +264,7 @@ mod tests { let category = "my"; let value1 = "xxx"; let value2 = "yyy"; - let tags1: EntryTags = vec![EntryTag::Plaintext("a".into(), "b".into())].into(); + let tags1: EntryTags = vec![("a".into(), "b".into())].into(); let tags2 = EntryTags::default(); let record = Record::builder() @@ -297,7 +297,7 @@ mod tests { let category = "my"; let value1 = "xxx"; let value2 = "yyy"; - let tags: EntryTags = vec![EntryTag::Plaintext("a".into(), "b".into())].into(); + let tags: EntryTags = vec![("a".into(), "b".into())].into(); let record = Record::builder() .name(name.into()) @@ -324,8 +324,8 @@ mod tests { let name = "foo"; let category = "my"; let value = "xxx"; - let tags1: EntryTags = vec![EntryTag::Plaintext("a".into(), "b".into())].into(); - let tags2: EntryTags = vec![EntryTag::Plaintext("c".into(), "d".into())].into(); + let tags1: EntryTags = vec![("a".into(), "b".into())].into(); + let tags2: EntryTags = vec![("c".into(), "d".into())].into(); let record = Record::builder() .name(name.into()) diff --git a/aries/aries_vcx_core/src/wallet/base_wallet/record.rs b/aries/aries_vcx_core/src/wallet/base_wallet/record.rs index 21c7f8cf92..6648455c8f 100644 --- a/aries/aries_vcx_core/src/wallet/base_wallet/record.rs +++ b/aries/aries_vcx_core/src/wallet/base_wallet/record.rs @@ -1,6 +1,6 @@ use typed_builder::TypedBuilder; -use crate::wallet::entry_tag::EntryTags; +use crate::wallet::entry_tags::EntryTags; #[derive(Debug, Default, Clone, TypedBuilder)] pub struct Record { diff --git a/aries/aries_vcx_core/src/wallet/entry_tag.rs b/aries/aries_vcx_core/src/wallet/entry_tags.rs similarity index 58% rename from aries/aries_vcx_core/src/wallet/entry_tag.rs rename to aries/aries_vcx_core/src/wallet/entry_tags.rs index d084c4a2a8..d52463e049 100644 --- a/aries/aries_vcx_core/src/wallet/entry_tag.rs +++ b/aries/aries_vcx_core/src/wallet/entry_tags.rs @@ -2,32 +2,26 @@ use std::fmt; use serde::{de::Visitor, ser::SerializeMap, Deserialize, Serialize}; -#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord)] -pub enum EntryTag { - Encrypted(String, String), - Plaintext(String, String), -} - -impl EntryTag { - pub fn from_pair(pair: (String, String)) -> Self { - if pair.0.starts_with('~') { - EntryTag::Plaintext(pair.0.trim_start_matches('~').into(), pair.1) - } else { - EntryTag::Encrypted(pair.0, pair.1) - } - } - - pub fn key(&self) -> &str { - match self { - Self::Encrypted(key, _) => key, - Self::Plaintext(key, _) => key, - } - } -} +// #[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord)] +// pub enum EntryTag { +// Tag(String, String), +// } + +// impl EntryTag { +// pub fn from_pair(pair: (String, String)) -> Self { +// Self::Tag(pair.0, pair.1) +// } + +// pub fn key(&self) -> &str { +// match self { +// Self::Tag(key, _) => key, +// } +// } +// } #[derive(Debug, Default, Clone, PartialEq)] pub struct EntryTags { - inner: Vec, + inner: Vec<(String, String)>, } impl Serialize for EntryTags { @@ -37,10 +31,7 @@ impl Serialize for EntryTags { { let mut map = serializer.serialize_map(Some(self.inner.len()))?; for tag in self.inner.iter() { - match tag { - EntryTag::Encrypted(key, val) => map.serialize_entry(&key, &val)?, - EntryTag::Plaintext(key, val) => map.serialize_entry(&format!("~{}", key), &val)?, - } + map.serialize_entry(&tag.0, &tag.1)? } map.end() } @@ -62,7 +53,7 @@ impl<'de> Visitor<'de> for EntryTagsVisitor { let mut tags = EntryTags::new(vec![]); while let Some(pair) = map.next_entry()? { - tags.add(EntryTag::from_pair(pair)); + tags.add(pair); } Ok(tags) @@ -79,14 +70,14 @@ impl<'de> Deserialize<'de> for EntryTags { } impl EntryTags { - pub fn new(inner: Vec) -> Self { + pub fn new(inner: Vec<(String, String)>) -> Self { let mut items = inner; items.sort(); Self { inner: items } } - pub fn add(&mut self, tag: EntryTag) { + pub fn add(&mut self, tag: (String, String)) { self.inner.push(tag); self.inner.sort(); } @@ -95,7 +86,7 @@ impl EntryTags { self.inner.is_empty() } - pub fn into_inner(self) -> Vec { + pub fn into_inner(self) -> Vec<(String, String)> { self.inner } @@ -104,15 +95,14 @@ impl EntryTags { self.inner.sort(); } - pub fn remove(&mut self, tag: EntryTag) { - self.inner - .retain(|existing_tag| existing_tag.key() != tag.key()); + pub fn remove(&mut self, tag: (String, String)) { + self.inner.retain(|existing_tag| existing_tag.0 != tag.0); self.inner.sort(); } } impl IntoIterator for EntryTags { - type Item = EntryTag; + type Item = (String, String); type IntoIter = std::vec::IntoIter; @@ -121,8 +111,8 @@ impl IntoIterator for EntryTags { } } -impl FromIterator for EntryTags { - fn from_iter>(iter: T) -> Self { +impl FromIterator<(String, String)> for EntryTags { + fn from_iter>(iter: T) -> Self { let mut tags = Self::default(); for item in iter { @@ -132,8 +122,8 @@ impl FromIterator for EntryTags { } } -impl From> for EntryTags { - fn from(value: Vec) -> Self { +impl From> for EntryTags { + fn from(value: Vec<(String, String)>) -> Self { value.into_iter().fold(Self::default(), |mut memo, item| { memo.add(item); memo @@ -141,7 +131,7 @@ impl From> for EntryTags { } } -impl From for Vec { +impl From for Vec<(String, String)> { fn from(value: EntryTags) -> Self { value.inner } @@ -151,14 +141,11 @@ impl From for Vec { mod tests { use serde_json::json; - use crate::wallet::entry_tag::{EntryTag, EntryTags}; + use crate::wallet::entry_tags::EntryTags; #[test] fn test_entry_tags_serialize() { - let tags = EntryTags::new(vec![ - EntryTag::Plaintext("a".into(), "b".into()), - EntryTag::Encrypted("c".into(), "d".into()), - ]); + let tags = EntryTags::new(vec![("~a".into(), "b".into()), ("c".into(), "d".into())]); let res = serde_json::to_string(&tags).unwrap(); @@ -169,10 +156,7 @@ mod tests { fn test_entry_tags_deserialize() { let json = json!({"a":"b", "~c":"d"}); - let tags = EntryTags::new(vec![ - EntryTag::Encrypted("a".into(), "b".into()), - EntryTag::Plaintext("c".into(), "d".into()), - ]); + let tags = EntryTags::new(vec![("a".into(), "b".into()), ("~c".into(), "d".into())]); let res = serde_json::from_str(&json.to_string()).unwrap(); diff --git a/aries/aries_vcx_core/src/wallet/indy/indy_record_wallet.rs b/aries/aries_vcx_core/src/wallet/indy/indy_record_wallet.rs index fc8cf63f97..d298a852e5 100644 --- a/aries/aries_vcx_core/src/wallet/indy/indy_record_wallet.rs +++ b/aries/aries_vcx_core/src/wallet/indy/indy_record_wallet.rs @@ -4,12 +4,12 @@ use serde::Deserialize; use serde_json::Value; use vdrtools::Locator; -use super::{indy_tag::IndyTags, SEARCH_OPTIONS, WALLET_OPTIONS}; +use super::{indy_tags::IndyTags, SEARCH_OPTIONS, WALLET_OPTIONS}; use crate::{ errors::error::{AriesVcxCoreError, VcxCoreResult}, wallet::{ base_wallet::{record::Record, search_filter::SearchFilter, RecordWallet}, - entry_tag::EntryTags, + entry_tags::EntryTags, indy::IndySdkWallet, }, }; diff --git a/aries/aries_vcx_core/src/wallet/indy/indy_tag.rs b/aries/aries_vcx_core/src/wallet/indy/indy_tag.rs deleted file mode 100644 index 6161592c21..0000000000 --- a/aries/aries_vcx_core/src/wallet/indy/indy_tag.rs +++ /dev/null @@ -1,60 +0,0 @@ -use std::collections::HashMap; - -use crate::wallet::entry_tag::{EntryTag, EntryTags}; -struct IndyTag((String, String)); - -impl IndyTag { - pub fn new(pair: (String, String)) -> Self { - Self(pair) - } - - pub fn into_inner(self) -> (String, String) { - self.0 - } - - pub fn into_entry_tag(self) -> EntryTag { - let inner = self.into_inner(); - - EntryTag::from_pair(inner) - } - - pub fn from_entry_tag(tag: EntryTag) -> Self { - match tag { - EntryTag::Encrypted(key, val) => Self((key, val)), - EntryTag::Plaintext(key, val) => Self((format!("~{}", key), val)), - } - } -} - -pub(crate) struct IndyTags(HashMap); - -impl IndyTags { - pub fn new(map: HashMap) -> Self { - Self(map) - } - - pub fn into_inner(self) -> HashMap { - self.0 - } - - pub fn from_entry_tags(tags: EntryTags) -> Self { - let mut map = HashMap::new(); - let tags_vec: Vec<_> = tags - .into_iter() - .map(|tag| IndyTag::from_entry_tag(tag).into_inner()) - .collect(); - map.extend(tags_vec); - Self(map) - } - - pub fn into_entry_tags(self) -> EntryTags { - let mut items: Vec = self - .0 - .into_iter() - .map(|pair| IndyTag::new(pair).into_entry_tag()) - .collect(); - items.sort(); - - EntryTags::new(items) - } -} diff --git a/aries/aries_vcx_core/src/wallet/indy/indy_tags.rs b/aries/aries_vcx_core/src/wallet/indy/indy_tags.rs new file mode 100644 index 0000000000..722a99bd21 --- /dev/null +++ b/aries/aries_vcx_core/src/wallet/indy/indy_tags.rs @@ -0,0 +1,29 @@ +use std::collections::HashMap; + +use crate::wallet::entry_tags::EntryTags; + +pub(crate) struct IndyTags(HashMap); + +impl IndyTags { + pub fn new(map: HashMap) -> Self { + Self(map) + } + + pub fn into_inner(self) -> HashMap { + self.0 + } + + pub fn from_entry_tags(tags: EntryTags) -> Self { + let mut map = HashMap::new(); + let tags_vec: Vec<_> = tags.into_iter().collect(); + map.extend(tags_vec); + Self(map) + } + + pub fn into_entry_tags(self) -> EntryTags { + let mut items: Vec<(String, String)> = self.0.into_iter().collect(); + items.sort(); + + EntryTags::new(items) + } +} diff --git a/aries/aries_vcx_core/src/wallet/indy/mod.rs b/aries/aries_vcx_core/src/wallet/indy/mod.rs index 0d3e049724..12e861ffb4 100644 --- a/aries/aries_vcx_core/src/wallet/indy/mod.rs +++ b/aries/aries_vcx_core/src/wallet/indy/mod.rs @@ -2,13 +2,13 @@ use indy_api_types::domain::wallet::IndyRecord; use serde::{Deserialize, Serialize}; use typed_builder::TypedBuilder; -use self::indy_tag::IndyTags; +use self::indy_tags::IndyTags; use super::base_wallet::{record::Record, BaseWallet}; use crate::{errors::error::VcxCoreResult, WalletHandle}; mod indy_did_wallet; mod indy_record_wallet; -mod indy_tag; +mod indy_tags; pub mod internal; pub mod wallet; diff --git a/aries/aries_vcx_core/src/wallet/mock_wallet.rs b/aries/aries_vcx_core/src/wallet/mock_wallet.rs index 5d3cc071df..bf7560bd14 100644 --- a/aries/aries_vcx_core/src/wallet/mock_wallet.rs +++ b/aries/aries_vcx_core/src/wallet/mock_wallet.rs @@ -11,7 +11,7 @@ use super::{ use crate::{ errors::error::{AriesVcxCoreError, AriesVcxCoreErrorKind, VcxCoreResult}, utils::{self}, - wallet::entry_tag::EntryTags, + wallet::entry_tags::EntryTags, }; #[derive(Debug)] diff --git a/aries/aries_vcx_core/src/wallet/mod.rs b/aries/aries_vcx_core/src/wallet/mod.rs index 8c8b97d96a..d94145b889 100644 --- a/aries/aries_vcx_core/src/wallet/mod.rs +++ b/aries/aries_vcx_core/src/wallet/mod.rs @@ -1,6 +1,6 @@ pub mod agency_client_wallet; pub mod base_wallet; -pub mod entry_tag; +pub mod entry_tags; #[cfg(feature = "vdrtools_wallet")] pub mod indy; pub mod mock_wallet; diff --git a/aries/misc/legacy/libvcx_core/src/api_vcx/api_global/wallet.rs b/aries/misc/legacy/libvcx_core/src/api_vcx/api_global/wallet.rs index a858e5f1c1..524bea752b 100644 --- a/aries/misc/legacy/libvcx_core/src/api_vcx/api_global/wallet.rs +++ b/aries/misc/legacy/libvcx_core/src/api_vcx/api_global/wallet.rs @@ -19,7 +19,7 @@ use aries_vcx::{ }; use aries_vcx_core::wallet::{ base_wallet::{record::Record, DidWallet, RecordWallet}, - entry_tag::EntryTags, + entry_tags::EntryTags, indy::IndyWalletRecord, }; use futures::FutureExt;