diff --git a/aries_vcx/src/common/anoncreds.rs b/aries_vcx/src/common/anoncreds.rs index 115c4bbf15..843991c403 100644 --- a/aries_vcx/src/common/anoncreds.rs +++ b/aries_vcx/src/common/anoncreds.rs @@ -26,7 +26,7 @@ pub mod integration_tests { let proof_req = "{"; let anoncreds = Arc::clone(&setup.profile).inject_anoncreds(); let result = anoncreds - .prover_get_credentials_for_proof_req(&proof_req) + .prover_get_credentials_for_proof_req(proof_req) .await; assert_eq!( result.unwrap_err().kind(), diff --git a/aries_vcx/src/common/ledger/transactions.rs b/aries_vcx/src/common/ledger/transactions.rs index 6066818c54..3a4ec26983 100644 --- a/aries_vcx/src/common/ledger/transactions.rs +++ b/aries_vcx/src/common/ledger/transactions.rs @@ -107,9 +107,8 @@ pub async fn into_did_doc( let mut did_doc: AriesDidDoc = AriesDidDoc::default(); let (service_endpoint, recipient_keys, routing_keys) = match invitation { AnyInvitation::Con(Invitation { - id, content: InvitationContent::Public(content), - decorators, + .. }) => { did_doc.set_id(content.did.to_string()); let service = get_service(indy_ledger, &content.did) @@ -130,7 +129,7 @@ pub async fn into_did_doc( AnyInvitation::Con(Invitation { id, content: InvitationContent::Pairwise(content), - decorators, + .. }) => { did_doc.set_id(id.clone()); ( @@ -140,13 +139,12 @@ pub async fn into_did_doc( ) } AnyInvitation::Con(Invitation { - id, - content: InvitationContent::PairwiseDID(content), - decorators, + content: InvitationContent::PairwiseDID(_content), + .. }) => { return Err(AriesVcxError::from_msg( AriesVcxErrorKind::InvalidDid, - format!("PairwiseDID invitation not supported yet!"), + "PairwiseDID invitation not supported yet!", )) } AnyInvitation::Oob(invitation) => { @@ -336,7 +334,7 @@ pub async fn add_attr( did: &str, attr: &str, ) -> VcxResult<()> { - let res = indy_ledger_write.add_attr(did, &attr).await?; + let res = indy_ledger_write.add_attr(did, attr).await?; check_response(&res) } @@ -365,7 +363,7 @@ pub async fn clear_attr( .map_err(|err| err.into()) } -pub(self) fn check_response(response: &str) -> VcxResult<()> { +fn check_response(response: &str) -> VcxResult<()> { if settings::indy_mocks_enabled() { return Ok(()); } diff --git a/aries_vcx/src/common/primitives/credential_definition.rs b/aries_vcx/src/common/primitives/credential_definition.rs index 4846430235..f661d6cda5 100644 --- a/aries_vcx/src/common/primitives/credential_definition.rs +++ b/aries_vcx/src/common/primitives/credential_definition.rs @@ -1,4 +1,4 @@ -use std::{fmt, sync::Arc}; +use std::sync::Arc; use aries_vcx_core::{ anoncreds::base_anoncreds::BaseAnonCreds, @@ -15,62 +15,40 @@ use crate::{ }, }; -macro_rules! enum_number { - ($name:ident { $($variant:ident = $value:expr, )* }) => { - #[derive(Clone, Copy, Debug, Eq, PartialEq)] - pub enum $name { - $($variant = $value,)* - } +#[derive(Clone, Copy, Debug, Eq, PartialEq, Deserialize, Default)] +#[serde(try_from = "u8")] +#[repr(u8)] +pub enum PublicEntityStateType { + Built = 0, + #[default] + Published = 1, +} - impl ::serde::Serialize for $name { - fn serialize(&self, serializer: S) -> Result - where S: ::serde::Serializer - { - // Serialize the enum as a u64. - serializer.serialize_u64(*self as u64) - } - } +impl ::serde::Serialize for PublicEntityStateType { + fn serialize(&self, serializer: S) -> Result + where + S: ::serde::Serializer, + { + serializer.serialize_u8(*self as u8) + } +} - impl<'de> ::serde::Deserialize<'de> for $name { - fn deserialize(deserializer: D) -> Result - where D: ::serde::Deserializer<'de> - { - struct Visitor; - - impl<'de> ::serde::de::Visitor<'de> for Visitor { - type Value = $name; - - fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { - formatter.write_str("positive integer") - } - - fn visit_u64(self, value: u64) -> Result<$name, E> - where E: ::serde::de::Error - { - // Rust does not come with a simple way of converting a - // number to an enum, so use a big `match`. - match value { - $( $value => Ok($name::$variant), )* - _ => Err(E::custom( - format!("unknown {} value: {}", - stringify!($name), value))), - } - } - } - - // Deserialize the enum from a u64. - deserializer.deserialize_u64(Visitor) - } +impl TryFrom for PublicEntityStateType { + type Error = String; + + fn try_from(value: u8) -> Result { + match value { + 0 => Ok(PublicEntityStateType::Built), + 1 => Ok(PublicEntityStateType::Published), + _ => Err(format!( + "unknown {} value: {}", + stringify!(PublicEntityStateType), + value + )), } } } -enum_number!(PublicEntityStateType -{ - Built = 0, - Published = 1, -}); - #[derive(Clone, Deserialize, Debug, Serialize, PartialEq, Eq, Default)] pub struct CredentialDef { #[serde(alias = "cred_def_id")] @@ -102,12 +80,6 @@ pub struct RevocationDetails { pub max_creds: Option, } -impl Default for PublicEntityStateType { - fn default() -> Self { - PublicEntityStateType::Published - } -} - async fn _try_get_cred_def_from_ledger( ledger: &Arc, issuer_did: &str, @@ -193,7 +165,7 @@ impl CredentialDef { self.id ); if let Some(ledger_cred_def_json) = - _try_get_cred_def_from_ledger(&ledger_read, &self.issuer_did, &self.id).await? + _try_get_cred_def_from_ledger(ledger_read, &self.issuer_did, &self.id).await? { return Err(AriesVcxError::from_msg( AriesVcxErrorKind::CredDefAlreadyCreated, diff --git a/aries_vcx/src/common/primitives/revocation_registry_delta.rs b/aries_vcx/src/common/primitives/revocation_registry_delta.rs index cf06bb5220..e446b87c9b 100644 --- a/aries_vcx/src/common/primitives/revocation_registry_delta.rs +++ b/aries_vcx/src/common/primitives/revocation_registry_delta.rs @@ -1,7 +1,3 @@ -use std::sync::Arc; - -use aries_vcx_core::ledger::base_ledger::AnoncredsLedgerRead; - use crate::errors::error::prelude::*; #[derive(Clone, Deserialize, Debug, Serialize, Default)] @@ -34,7 +30,7 @@ impl RevocationRegistryDeltaValue { impl RevocationRegistryDelta { pub async fn create_from_ledger(rev_reg_delta_json: &str) -> VcxResult { - serde_json::from_str(&rev_reg_delta_json).map_err(|err| { + serde_json::from_str(rev_reg_delta_json).map_err(|err| { AriesVcxError::from_msg( AriesVcxErrorKind::SerializationError, format!( diff --git a/aries_vcx/src/common/proofs/proof_request.rs b/aries_vcx/src/common/proofs/proof_request.rs index 729915deb7..02cf300aa6 100644 --- a/aries_vcx/src/common/proofs/proof_request.rs +++ b/aries_vcx/src/common/proofs/proof_request.rs @@ -328,7 +328,7 @@ mod unit_tests { let request = ProofRequestData::create(&anoncreds, "") .await .unwrap() - .set_requested_attributes_as_string(requested_attrs.into()) + .set_requested_attributes_as_string(requested_attrs) .unwrap(); let mut expected_req_attrs: HashMap = HashMap::new(); @@ -359,7 +359,7 @@ mod unit_tests { let err = ProofRequestData::create(&anoncreds, "") .await .unwrap() - .set_requested_attributes_as_string(requested_attrs.into()) + .set_requested_attributes_as_string(requested_attrs) .unwrap_err(); assert_eq!(AriesVcxErrorKind::InvalidProofRequest, err.kind()); diff --git a/aries_vcx/src/common/proofs/prover/prover_internal.rs b/aries_vcx/src/common/proofs/prover/prover_internal.rs index eaa0db3c41..164cf45bbf 100644 --- a/aries_vcx/src/common/proofs/prover/prover_internal.rs +++ b/aries_vcx/src/common/proofs/prover/prover_internal.rs @@ -112,7 +112,7 @@ pub fn credential_def_identifiers( credential_referent: cred_info.referent.clone(), schema_id: cred_info.schema_id.clone(), cred_def_id: cred_info.cred_def_id.clone(), - revocation_interval: _get_revocation_interval(&referent, proof_req)?, + revocation_interval: _get_revocation_interval(referent, proof_req)?, timestamp: None, rev_reg_id: cred_info.rev_reg_id.clone(), cred_rev_id: cred_info.cred_rev_id.clone(), @@ -337,17 +337,14 @@ pub mod unit_tests { use aries_vcx_core::ledger::indy::pool::test_utils::get_temp_dir_path; use super::*; - use crate::{ - core::profile::vdrtools_profile::VdrtoolsProfile, - utils::{ - constants::{ - ADDRESS_CRED_DEF_ID, ADDRESS_CRED_ID, ADDRESS_CRED_REV_ID, ADDRESS_REV_REG_ID, - ADDRESS_SCHEMA_ID, CRED_DEF_ID, CRED_REV_ID, LICENCE_CRED_ID, REV_REG_ID, - REV_STATE_JSON, SCHEMA_ID, - }, - devsetup::*, - mockdata::profile::{mock_anoncreds::MockAnoncreds, mock_ledger::MockLedger}, + use crate::utils::{ + constants::{ + ADDRESS_CRED_DEF_ID, ADDRESS_CRED_ID, ADDRESS_CRED_REV_ID, ADDRESS_REV_REG_ID, + ADDRESS_SCHEMA_ID, CRED_DEF_ID, CRED_REV_ID, LICENCE_CRED_ID, REV_REG_ID, + REV_STATE_JSON, SCHEMA_ID, }, + devsetup::*, + mockdata::profile::{mock_anoncreds::MockAnoncreds, mock_ledger::MockLedger}, }; fn proof_req_no_interval() -> ProofRequestData { @@ -401,7 +398,7 @@ pub mod unit_tests { let credential_def = build_cred_defs_json_prover(&ledger_read, &creds) .await .unwrap(); - assert!(credential_def.len() > 0); + assert!(!credential_def.is_empty()); assert!(credential_def .contains(r#""id":"V4SGRU86Z58d6TV7PBUe6f:3:CL:47:tag1","schemaId":"47""#)); } @@ -448,7 +445,7 @@ pub mod unit_tests { let schemas = build_schemas_json_prover(&ledger_read, &creds) .await .unwrap(); - assert!(schemas.len() > 0); + assert!(!schemas.is_empty()); assert!(schemas.contains( r#""id":"2hoqvcwupRTUNkXn6ArYzs:2:test-licence:4.4.4","name":"test-licence""# )); @@ -691,7 +688,7 @@ pub mod unit_tests { "zip_2": { "name": "zip_2" } }, "requested_predicates": {}, - "non_revoked": {"from": 098, "to": 123} + "non_revoked": {"from": 98, "to": 123} }); let proof_req: ProofRequestData = serde_json::from_value(proof_req).unwrap(); let requested_credential = build_requested_credentials_json( @@ -747,7 +744,7 @@ pub mod unit_tests { "zip_2": { "name": "zip" } }, "requested_predicates": {}, - "non_revoked": {"from": 098, "to": 123} + "non_revoked": {"from": 98, "to": 123} }); let proof_req: ProofRequestData = serde_json::from_value(proof_req).unwrap(); @@ -771,7 +768,7 @@ pub mod unit_tests { // when attribute interval is None, defaults to proof req interval let interval = Some(NonRevokedInterval { - from: Some(098), + from: Some(98), to: Some(123), }); assert_eq!( diff --git a/aries_vcx/src/common/proofs/verifier/verifier.rs b/aries_vcx/src/common/proofs/verifier/verifier.rs index f4d3fbf3b8..dbd75e0c3c 100644 --- a/aries_vcx/src/common/proofs/verifier/verifier.rs +++ b/aries_vcx/src/common/proofs/verifier/verifier.rs @@ -91,7 +91,7 @@ pub mod integration_tests { anoncreds_holder, ledger_read, ledger_write, - &did, + did, DEFAULT_SCHEMA_ATTRS, ) .await; @@ -135,7 +135,7 @@ pub mod integration_tests { .to_string(); let cred_def_json: serde_json::Value = - serde_json::from_str(&cred_def.get_cred_def_json()).unwrap(); + serde_json::from_str(cred_def.get_cred_def_json()).unwrap(); let cred_defs = json!({ cred_def.get_cred_def_id(): cred_def_json, }) @@ -173,7 +173,7 @@ pub mod integration_tests { anoncreds_holder, ledger_read, ledger_write, - &did, + did, DEFAULT_SCHEMA_ATTRS, ) .await; @@ -197,9 +197,8 @@ pub mod integration_tests { }) .to_string(); - let requested_credentials_json; - if include_predicate_cred { - requested_credentials_json = json!({ + let requested_credentials_json = if include_predicate_cred { + json!({ "self_attested_attributes":{ "self_attest_3": "my_self_attested_val" }, @@ -210,9 +209,9 @@ pub mod integration_tests { "zip_3": {"cred_id": cred_id} } }) - .to_string(); + .to_string() } else { - requested_credentials_json = json!({ + json!({ "self_attested_attributes":{ "self_attest_3": "my_self_attested_val" }, @@ -222,8 +221,8 @@ pub mod integration_tests { "requested_predicates":{ } }) - .to_string(); - } + .to_string() + }; let schema_json: serde_json::Value = serde_json::from_str(&schema.schema_json).unwrap(); let schemas = json!({ @@ -343,17 +342,14 @@ pub mod integration_tests { .await .unwrap(); - assert_eq!( - validate_indy_proof( - &setup.profile.inject_anoncreds_ledger_read(), - &setup.profile.inject_anoncreds(), - &prover_proof_json, - &proof_req_json - ) - .await - .unwrap(), - true - ); + assert!(validate_indy_proof( + &setup.profile.inject_anoncreds_ledger_read(), + &setup.profile.inject_anoncreds(), + &prover_proof_json, + &proof_req_json + ) + .await + .unwrap()); }) .await; } @@ -443,17 +439,14 @@ pub mod integration_tests { let mut proof_req_json: serde_json::Value = serde_json::from_str(&proof_req_json).unwrap(); proof_req_json["requested_attributes"]["attribute_0"]["restrictions"] = json!({}); - assert_eq!( - validate_indy_proof( - &setup.profile.inject_anoncreds_ledger_read(), - &setup.profile.inject_anoncreds(), - &prover_proof_json, - &proof_req_json.to_string() - ) - .await - .unwrap(), - true - ); + assert!(validate_indy_proof( + &setup.profile.inject_anoncreds_ledger_read(), + &setup.profile.inject_anoncreds(), + &prover_proof_json, + &proof_req_json.to_string() + ) + .await + .unwrap()); }) .await; } @@ -503,7 +496,7 @@ pub mod integration_tests { ) .await; let cred_def_json: serde_json::Value = - serde_json::from_str(&cred_def.get_cred_def_json()).unwrap(); + serde_json::from_str(cred_def.get_cred_def_json()).unwrap(); let schema_json: serde_json::Value = serde_json::from_str(&schema.schema_json).unwrap(); let anoncreds = Arc::clone(&setup.profile).inject_anoncreds(); @@ -528,17 +521,14 @@ pub mod integration_tests { ) .await .unwrap(); - assert_eq!( - validate_indy_proof( - &setup.profile.inject_anoncreds_ledger_read(), - &setup.profile.inject_anoncreds(), - &prover_proof_json, - &proof_req_json - ) - .await - .unwrap(), - true - ); + assert!(validate_indy_proof( + &setup.profile.inject_anoncreds_ledger_read(), + &setup.profile.inject_anoncreds(), + &prover_proof_json, + &proof_req_json + ) + .await + .unwrap()); let mut proof_obj: serde_json::Value = serde_json::from_str(&prover_proof_json).unwrap(); diff --git a/aries_vcx/src/common/proofs/verifier/verifier_internal.rs b/aries_vcx/src/common/proofs/verifier/verifier_internal.rs index 8c0a420ee9..3c4a8d8df0 100644 --- a/aries_vcx/src/common/proofs/verifier/verifier_internal.rs +++ b/aries_vcx/src/common/proofs/verifier/verifier_internal.rs @@ -229,11 +229,7 @@ pub async fn build_rev_reg_json( #[allow(clippy::unwrap_used)] pub mod unit_tests { use super::*; - use crate::utils::{ - constants::*, - devsetup::*, - mockdata::profile::{mock_anoncreds::MockAnoncreds, mock_ledger::MockLedger}, - }; + use crate::utils::{constants::*, devsetup::*, mockdata::profile::mock_ledger::MockLedger}; #[tokio::test] async fn test_build_cred_defs_json_verifier_with_multiple_credentials() { diff --git a/aries_vcx/src/common/test_utils.rs b/aries_vcx/src/common/test_utils.rs index 94a1118895..1831011185 100644 --- a/aries_vcx/src/common/test_utils.rs +++ b/aries_vcx/src/common/test_utils.rs @@ -34,7 +34,7 @@ pub async fn create_and_write_test_schema( ) -> Schema { let (schema_id, schema_json) = anoncreds .issuer_create_schema( - &submitter_did, + submitter_did, &generate_random_schema_name(), &generate_random_schema_version(), attr_list, @@ -42,7 +42,7 @@ pub async fn create_and_write_test_schema( .await .unwrap(); - let _response = ledger_write + ledger_write .publish_schema(&schema_json, submitter_did, None) .await .unwrap(); @@ -104,7 +104,7 @@ pub async fn create_and_write_credential( ) -> String { // TODO: Inject credential_data from caller let credential_data = r#"{"address1": ["123 Main St"], "address2": ["Suite 3"], "city": ["Draper"], "state": ["UT"], "zip": ["84000"]}"#; - let encoded_attributes = encode_attributes(&credential_data).unwrap(); + let encoded_attributes = encode_attributes(credential_data).unwrap(); let offer = anoncreds_issuer .issuer_create_credential_offer(&cred_def.get_cred_def_id()) @@ -112,7 +112,7 @@ pub async fn create_and_write_credential( .unwrap(); let (req, req_meta) = anoncreds_holder .prover_create_credential_req( - &institution_did, + institution_did, &offer, cred_def.get_cred_def_json(), settings::DEFAULT_LINK_SECRET_ALIAS, @@ -135,7 +135,7 @@ pub async fn create_and_write_credential( .await .unwrap(); - let cred_id = anoncreds_holder + anoncreds_holder .prover_store_credential( None, &req_meta, @@ -144,6 +144,5 @@ pub async fn create_and_write_credential( rev_reg_def_json.as_deref(), ) .await - .unwrap(); - cred_id + .unwrap() } diff --git a/aries_vcx/src/core/profile/ledger.rs b/aries_vcx/src/core/profile/ledger.rs index 9910b1c52a..62e43427ac 100644 --- a/aries_vcx/src/core/profile/ledger.rs +++ b/aries_vcx/src/core/profile/ledger.rs @@ -16,6 +16,8 @@ use aries_vcx_core::{ }; use crate::errors::error::VcxResult; +type ArcIndyVdrLedgerRead = Arc>; +type ArcIndyVdrLedgerWrite = Arc>; pub struct VcxPoolConfig { pub genesis_file_path: String, @@ -26,10 +28,7 @@ pub struct VcxPoolConfig { pub fn build_ledger_components( wallet: Arc, pool_config: VcxPoolConfig, -) -> VcxResult<( - Arc>, - Arc>, -)> { +) -> VcxResult<(ArcIndyVdrLedgerRead, ArcIndyVdrLedgerWrite)> { let indy_vdr_config = match pool_config.indy_vdr_config { None => PoolConfig::default(), Some(cfg) => cfg, @@ -55,7 +54,7 @@ pub fn build_ledger_components( let ledger_read = Arc::new(ledger_read); let ledger_write = Arc::new(ledger_write); - return Ok((ledger_read, ledger_write)); + Ok((ledger_read, ledger_write)) } pub fn indyvdr_build_ledger_read( diff --git a/aries_vcx/src/core/profile/vdrtools_profile.rs b/aries_vcx/src/core/profile/vdrtools_profile.rs index 9fc387ab2b..58db443883 100644 --- a/aries_vcx/src/core/profile/vdrtools_profile.rs +++ b/aries_vcx/src/core/profile/vdrtools_profile.rs @@ -7,7 +7,6 @@ use aries_vcx_core::{ TxnAuthrAgrmtOptions, }, wallet::{base_wallet::BaseWallet, indy::IndySdkWallet}, - WalletHandle, }; use async_trait::async_trait; @@ -71,14 +70,14 @@ impl Profile for VdrtoolsProfile { } #[cfg(feature = "migration")] - fn wallet_handle(&self) -> Option { + fn wallet_handle(&self) -> Option { Some(self.wallet.wallet_handle) } fn update_taa_configuration(&self, _taa_options: TxnAuthrAgrmtOptions) -> VcxResult<()> { Err(AriesVcxError::from_msg( AriesVcxErrorKind::ActionNotSupported, - format!("update_taa_configuration no implemented for VdrtoolsProfile"), + "update_taa_configuration no implemented for VdrtoolsProfile", )) } } diff --git a/aries_vcx/src/errors/mapping_others.rs b/aries_vcx/src/errors/mapping_others.rs index c2e8db1e9c..0cd858408c 100644 --- a/aries_vcx/src/errors/mapping_others.rs +++ b/aries_vcx/src/errors/mapping_others.rs @@ -119,7 +119,7 @@ impl From for AriesVcxError { AriesVcxCoreErrorKind::NoAgentInformation => AriesVcxErrorKind::NoAgentInformation, AriesVcxCoreErrorKind::InvalidMessageFormat => AriesVcxErrorKind::InvalidMessageFormat, }; - AriesVcxError::from_msg(kind, format!("AriesVcxCoreError: {}", err.to_string())) + AriesVcxError::from_msg(kind, format!("AriesVcxCoreError: {}", err)) } } @@ -216,6 +216,6 @@ impl From for AriesVcxCoreError { AriesVcxErrorKind::NoAgentInformation => AriesVcxCoreErrorKind::NoAgentInformation, AriesVcxErrorKind::InvalidMessageFormat => AriesVcxCoreErrorKind::InvalidMessageFormat, }; - AriesVcxCoreError::from_msg(kind, format!("AriesVcxError: {}", err.to_string())) + AriesVcxCoreError::from_msg(kind, format!("AriesVcxError: {}", err)) } } diff --git a/aries_vcx/src/handlers/connection/mediated_connection.rs b/aries_vcx/src/handlers/connection/mediated_connection.rs index 42f7592488..11f7a3cf1e 100644 --- a/aries_vcx/src/handlers/connection/mediated_connection.rs +++ b/aries_vcx/src/handlers/connection/mediated_connection.rs @@ -543,7 +543,7 @@ impl MediatedConnection { &query.id, &supported_protocols ); - respond_discovery_query(&wallet, query, &did_doc, pw_vk, supported_protocols) + respond_discovery_query(wallet, query, &did_doc, pw_vk, supported_protocols) .await?; } AriesMessage::DiscoverFeatures(DiscoverFeatures::Disclose(disclose)) => { diff --git a/aries_vcx/src/handlers/issuance/holder.rs b/aries_vcx/src/handlers/issuance/holder.rs index 75b886fff6..5e0b3f045d 100644 --- a/aries_vcx/src/handlers/issuance/holder.rs +++ b/aries_vcx/src/handlers/issuance/holder.rs @@ -118,9 +118,8 @@ impl Holder { pub fn get_msg_credential_request(&self) -> VcxResult { match self.holder_sm.state { HolderFullState::RequestSet(ref state) => { - let mut msg: RequestCredential = state.msg_credential_request.clone().into(); - let mut timing = Timing::default(); - timing.out_time = Some(Utc::now()); + let mut msg: RequestCredential = state.msg_credential_request.clone(); + let timing = Timing::builder().out_time(Utc::now()).build(); msg.decorators.timing = Some(timing); Ok(msg) } @@ -283,16 +282,11 @@ impl Holder { pub fn get_final_message(&self) -> VcxResult> { match &self.holder_sm.state { - HolderFullState::Finished(state) => { - if let Some(ack_requested) = state.ack_requested { - if ack_requested { - let ack_msg = build_credential_ack(&self.get_thread_id()?); - return Ok(Some(ack_msg.into())); - } - } + HolderFullState::Finished(state) if Some(true) == state.ack_requested => { + let ack_msg = build_credential_ack(&self.get_thread_id()?); + Ok(Some(ack_msg.into())) } - _ => {} - }; - return Ok(None); + _ => Ok(None), + } } } diff --git a/aries_vcx/src/handlers/out_of_band/receiver.rs b/aries_vcx/src/handlers/out_of_band/receiver.rs index e987558920..e8205a1c26 100644 --- a/aries_vcx/src/handlers/out_of_band/receiver.rs +++ b/aries_vcx/src/handlers/out_of_band/receiver.rs @@ -69,7 +69,7 @@ impl OutOfBandReceiver { match connection.bootstrap_did_doc() { Some(did_doc) => { if let OobService::Did(did) = service { - if did.to_string() == did_doc.id { + if did == &did_doc.id { return Ok(Some(connection)); } }; @@ -130,7 +130,7 @@ impl OutOfBandReceiver { fn did_doc_matches_service_did(service: &OobService, did_doc: &AriesDidDoc) -> bool { match service { - OobService::Did(did) => did.to_string() == did_doc.id, + OobService::Did(did) => did == &did_doc.id, _ => false, } } @@ -154,8 +154,7 @@ impl OutOfBandReceiver { .content .requests_attach .as_ref() - .map(|v| v.get(0)) - .flatten() + .and_then(|v| v.get(0)) { let AttachmentType::Base64(encoded_attach) = &attach.data.content else { return Err(AriesVcxError::from_msg( diff --git a/aries_vcx/src/handlers/revocation_notification/mod.rs b/aries_vcx/src/handlers/revocation_notification/mod.rs index 12711f331d..1dcdfc7ad0 100644 --- a/aries_vcx/src/handlers/revocation_notification/mod.rs +++ b/aries_vcx/src/handlers/revocation_notification/mod.rs @@ -58,13 +58,13 @@ pub mod test_utils { ) -> VcxResult> { let mut messages = Vec::::new(); for (uid, message) in connection - .get_messages_noauth(&agency_client) + .get_messages_noauth(agency_client) .await? .into_iter() { if let AriesMessage::Revocation(Revocation::Revoke(message)) = message { connection - .update_message_status(&uid, &agency_client) + .update_message_status(&uid, agency_client) .await .ok(); messages.push(message); @@ -79,13 +79,13 @@ pub mod test_utils { ) -> VcxResult> { let mut messages = Vec::::new(); for (uid, message) in connection - .get_messages_noauth(&agency_client) + .get_messages_noauth(agency_client) .await? .into_iter() { if let AriesMessage::Revocation(Revocation::Ack(message)) = message { connection - .update_message_status(&uid, &agency_client) + .update_message_status(&uid, agency_client) .await .ok(); messages.push(message); diff --git a/aries_vcx/src/handlers/util.rs b/aries_vcx/src/handlers/util.rs index 1141b78a09..e6009e4605 100644 --- a/aries_vcx/src/handlers/util.rs +++ b/aries_vcx/src/handlers/util.rs @@ -1,5 +1,4 @@ use messages::{ - decorators::attachment::Attachment, msg_fields::protocols::{ connection::{invitation::Invitation, Connection}, cred_issuance::CredentialIssuance, diff --git a/aries_vcx/src/protocols/connection/invitee/mod.rs b/aries_vcx/src/protocols/connection/invitee/mod.rs index ba6cf47f42..f6a7023ea5 100644 --- a/aries_vcx/src/protocols/connection/invitee/mod.rs +++ b/aries_vcx/src/protocols/connection/invitee/mod.rs @@ -94,8 +94,10 @@ impl InviteeConnection { let id = Uuid::new_v4().to_string(); - let mut did_doc = AriesDidDoc::default(); - did_doc.id = self.pairwise_info.pw_did.to_string(); + let mut did_doc = AriesDidDoc { + id: self.pairwise_info.pw_did.to_string(), + ..Default::default() + }; did_doc.set_service_endpoint(service_endpoint); did_doc.set_routing_keys(routing_keys); did_doc.set_recipient_keys(recipient_keys); diff --git a/aries_vcx/src/protocols/issuance/issuer/state_machine.rs b/aries_vcx/src/protocols/issuance/issuer/state_machine.rs index d5fc31fb19..4f984f9024 100644 --- a/aries_vcx/src/protocols/issuance/issuer/state_machine.rs +++ b/aries_vcx/src/protocols/issuance/issuer/state_machine.rs @@ -469,9 +469,9 @@ impl IssuerSM { match self.state { IssuerFullState::CredentialSet(ref state_data) => { let mut msg_issue_credential: IssueCredential = - state_data.msg_issue_credential.clone().into(); - let mut timing = Timing::default(); - timing.out_time = Some(Utc::now()); + state_data.msg_issue_credential.clone(); + let timing = Timing::builder().out_time(Utc::now()).build(); + msg_issue_credential.decorators.timing = Some(timing); Ok(msg_issue_credential) } @@ -578,7 +578,7 @@ async fn create_credential( if !matches_opt_thread_id!(request, thread_id.as_str()) { return Err(AriesVcxError::from_msg( AriesVcxErrorKind::InvalidJson, - format!("Cannot handle credential request: thread id does not match"), + "Cannot handle credential request: thread id does not match", )); }; diff --git a/aries_vcx/src/protocols/proof_presentation/verifier/state_machine.rs b/aries_vcx/src/protocols/proof_presentation/verifier/state_machine.rs index e6336a5d04..a3a0789ac5 100644 --- a/aries_vcx/src/protocols/proof_presentation/verifier/state_machine.rs +++ b/aries_vcx/src/protocols/proof_presentation/verifier/state_machine.rs @@ -269,7 +269,7 @@ impl VerifierSM { .verify_presentation(ledger, anoncreds, &presentation, &self.thread_id) .await; - let sm = match verification_result { + match verification_result { Ok(()) => VerifierFullState::Finished( (state, presentation, PresentationVerificationStatus::Valid).into(), ), @@ -287,8 +287,7 @@ impl VerifierSM { } } } - }; - sm + } } s => { warn!("Unable to verify presentation in state {}", s); @@ -322,7 +321,7 @@ impl VerifierSM { } }, }, - s @ _ => Err(AriesVcxError::from_msg( + s => Err(AriesVcxError::from_msg( AriesVcxErrorKind::InvalidState, format!("Cannot get final message in this state: {:?}", s), )), diff --git a/aries_vcx/src/protocols/trustping/mod.rs b/aries_vcx/src/protocols/trustping/mod.rs index 7c5973bf9f..c8f4f7712a 100644 --- a/aries_vcx/src/protocols/trustping/mod.rs +++ b/aries_vcx/src/protocols/trustping/mod.rs @@ -10,14 +10,15 @@ use messages::{ }; pub fn build_ping(request_response: bool, comment: Option) -> Ping { - let mut content = PingContent::default(); - content.response_requested = request_response; - content.comment = comment; + let content = PingContent::builder().response_requested(request_response); + let content = match comment { + None => content.build(), + Some(comment) => content.comment(comment).build(), + }; - let mut decorators = PingDecorators::default(); - let mut timing = Timing::default(); - timing.out_time = Some(Utc::now()); - decorators.timing = Some(timing); + let decorators = PingDecorators::builder() + .timing(Timing::builder().out_time(Utc::now()).build()) + .build(); Ping::builder() .id(Uuid::new_v4().to_string()) diff --git a/aries_vcx/src/utils/devsetup.rs b/aries_vcx/src/utils/devsetup.rs index ee56d13d25..c455e132be 100644 --- a/aries_vcx/src/utils/devsetup.rs +++ b/aries_vcx/src/utils/devsetup.rs @@ -150,7 +150,7 @@ impl Drop for SetupMocks { pub async fn dev_setup_wallet_indy(key_seed: &str) -> (String, WalletHandle) { info!("dev_setup_wallet_indy >>"); let config_wallet = WalletConfig { - wallet_name: format!("wallet_{}", uuid::Uuid::new_v4().to_string()), + wallet_name: format!("wallet_{}", uuid::Uuid::new_v4()), wallet_key: settings::DEFAULT_WALLET_KEY.into(), wallet_key_derivation: settings::WALLET_KDF_RAW.into(), wallet_type: None, @@ -226,6 +226,7 @@ pub async fn dev_build_profile_vdr_proxy_ledger(wallet: Arc) -> A Arc::new(VdrProxyProfile::init(wallet, client).await.unwrap()) } +#[allow(unreachable_code)] pub async fn dev_build_featured_profile( genesis_file_path: String, wallet: Arc, diff --git a/aries_vcx/src/utils/filters.rs b/aries_vcx/src/utils/filters.rs index 8bc3f75ff2..6015b6119f 100644 --- a/aries_vcx/src/utils/filters.rs +++ b/aries_vcx/src/utils/filters.rs @@ -9,7 +9,7 @@ use serde_json; use crate::{errors::error::prelude::*, handlers::util::get_attach_as_string}; -fn __accommodate_macro(attachments: &Vec) -> VcxResult { +fn __accommodate_macro(attachments: &[Attachment]) -> VcxResult { Ok(get_attach_as_string!(attachments)) } diff --git a/aries_vcx/src/utils/mod.rs b/aries_vcx/src/utils/mod.rs index d90815d617..71007aa636 100644 --- a/aries_vcx/src/utils/mod.rs +++ b/aries_vcx/src/utils/mod.rs @@ -1,4 +1,4 @@ -use std::{env, path::PathBuf, sync::Arc}; +use std::sync::Arc; use aries_vcx_core::wallet::base_wallet::BaseWallet; use diddoc_legacy::aries::diddoc::AriesDidDoc; @@ -29,19 +29,6 @@ macro_rules! secret { }}; } -#[cfg(test)] -macro_rules! map ( - { $($key:expr => $value:expr),+ } => { - { - let mut m = std::collections::HashMap::new(); - $( - m.insert($key, $value); - )+ - m - } - }; -); - #[rustfmt::skip] pub mod constants; pub mod file; diff --git a/aries_vcx/src/utils/openssl.rs b/aries_vcx/src/utils/openssl.rs index 1677ab5a59..904d9acab7 100644 --- a/aries_vcx/src/utils/openssl.rs +++ b/aries_vcx/src/utils/openssl.rs @@ -10,7 +10,7 @@ pub fn encode(s: &str) -> VcxResult { let mut hasher = Sha256::new(); hasher.update(s.as_bytes()); let hash = hasher.finalize(); - let bignum = BigUint::from_bytes_be(&hash.as_slice()); + let bignum = BigUint::from_bytes_be(hash.as_slice()); let encoded = bignum.to_str_radix(10); Ok(encoded) } diff --git a/aries_vcx/src/utils/serialization.rs b/aries_vcx/src/utils/serialization.rs index 8d89ebe503..f776eb760a 100644 --- a/aries_vcx/src/utils/serialization.rs +++ b/aries_vcx/src/utils/serialization.rs @@ -87,7 +87,7 @@ mod tests { } "#; - let result = serde_json::from_str(&serialized); + let result = serde_json::from_str(serialized); let ans: SerializableObjectWithState, String> = result.unwrap(); let (data, state, source_id, thread_id) = match ans { diff --git a/aries_vcx/src/utils/validation.rs b/aries_vcx/src/utils/validation.rs index 31fd34a5a8..be4781f182 100644 --- a/aries_vcx/src/utils/validation.rs +++ b/aries_vcx/src/utils/validation.rs @@ -50,7 +50,7 @@ mod unit_tests { let _setup = SetupDefaults::init(); let to_did = "8XFh8yBzrpJQmNyZzgoTqB"; - match validate_did(&to_did) { + match validate_did(to_did) { Err(_) => panic!("Should be valid did"), Ok(x) => assert_eq!(x, to_did.to_string()), } @@ -61,7 +61,7 @@ mod unit_tests { let _setup = SetupDefaults::init(); let to_did = "8XFh8yBzrpJQmNyZzgoT"; - match validate_did(&to_did) { + match validate_did(to_did) { Err(x) => assert_eq!(x.kind(), AriesVcxErrorKind::InvalidDid), Ok(_) => panic!("Should be invalid did"), } @@ -72,7 +72,7 @@ mod unit_tests { let _setup = SetupDefaults::init(); let to_did = "8*Fh8yBzrpJQmNyZzgoTqB"; - match validate_did(&to_did) { + match validate_did(to_did) { Err(x) => assert_eq!(x.kind(), AriesVcxErrorKind::NotBase58), Ok(_) => panic!("Should be invalid did"), } diff --git a/aries_vcx/tests/test_credential_retrieval.rs b/aries_vcx/tests/test_credential_retrieval.rs index 578eca080b..1696806090 100644 --- a/aries_vcx/tests/test_credential_retrieval.rs +++ b/aries_vcx/tests/test_credential_retrieval.rs @@ -12,7 +12,7 @@ use aries_vcx::{ proofs::proof_request::PresentationRequestData, test_utils::{ create_and_write_credential, create_and_write_test_cred_def, - create_and_write_test_rev_reg, create_and_write_test_schema, + create_and_write_test_schema, }, }, handlers::{ diff --git a/aries_vcx/tests/utils/scenarios/credential_issuance.rs b/aries_vcx/tests/utils/scenarios/credential_issuance.rs index cec0ccb322..06f6a8c031 100644 --- a/aries_vcx/tests/utils/scenarios/credential_issuance.rs +++ b/aries_vcx/tests/utils/scenarios/credential_issuance.rs @@ -45,7 +45,7 @@ pub async fn create_address_schema_creddef_revreg( let schema = create_and_write_test_schema( &anoncreds, &ledger_write, - &institution_did, + institution_did, &json!(attr_names_address_list()).to_string(), ) .await; @@ -53,7 +53,7 @@ pub async fn create_address_schema_creddef_revreg( &anoncreds, &ledger_read, &ledger_write, - &institution_did, + institution_did, &schema.schema_id, true, ) @@ -61,7 +61,7 @@ pub async fn create_address_schema_creddef_revreg( let rev_reg = create_and_write_test_rev_reg( &anoncreds, &ledger_write, - &institution_did, + institution_did, &cred_def.get_cred_def_id(), ) .await; diff --git a/aries_vcx/tests/utils/scenarios/proof_presentation.rs b/aries_vcx/tests/utils/scenarios/proof_presentation.rs index fdb3f5bec7..0bfb10511b 100644 --- a/aries_vcx/tests/utils/scenarios/proof_presentation.rs +++ b/aries_vcx/tests/utils/scenarios/proof_presentation.rs @@ -90,8 +90,7 @@ pub async fn accept_proof_proposal( verifier .set_presentation_request(presentation_request_data, None) .unwrap(); - let presentation_request = verifier.mark_presentation_request_sent().unwrap(); - presentation_request + verifier.mark_presentation_request_sent().unwrap() } pub async fn reject_proof_proposal(presentation_proposal: &ProposePresentation) -> ProblemReport { @@ -295,8 +294,8 @@ pub async fn verifier_create_proof_and_send_request( ) -> Verifier { let requested_attrs = requested_attrs_address( &institution.institution_did, - &schema_id, - &cred_def_id, + schema_id, + cred_def_id, None, None, ); @@ -327,7 +326,8 @@ pub async fn prover_select_credentials( .await .unwrap(); info!("prover_select_credentials >> retrieved_credentials: {retrieved_credentials:?}"); - let selected_credentials = match preselected_credentials { + + match preselected_credentials { Some(preselected_credentials) => { let credential_data = prover.presentation_request_data().unwrap(); match_preselected_credentials( @@ -338,9 +338,7 @@ pub async fn prover_select_credentials( ) } _ => retrieved_to_selected_credentials_simple(&retrieved_credentials, true), - }; - - selected_credentials + } } pub async fn prover_select_credentials_and_send_proof( @@ -352,7 +350,7 @@ pub async fn prover_select_credentials_and_send_proof( let selected_credentials = prover_select_credentials( &mut prover, alice, - presentation_request.into(), + presentation_request, preselected_credentials, ) .await; @@ -378,7 +376,7 @@ pub fn retrieved_to_selected_credentials_simple( let mut selected_credentials = SelectedCredentials::default(); for (referent, cred_array) in retrieved_credentials.credentials_by_referent.iter() { - if cred_array.len() > 0 { + if !cred_array.is_empty() { let first_cred = cred_array[0].clone(); let tails_dir = with_tails.then_some(get_temp_dir_path().to_str().unwrap().to_owned()); selected_credentials.select_credential_for_referent_from_retrieved( @@ -388,7 +386,7 @@ pub fn retrieved_to_selected_credentials_simple( ); } } - return selected_credentials; + selected_credentials } pub fn match_preselected_credentials( @@ -430,7 +428,8 @@ pub fn match_preselected_credentials( tails_dir, ); } - return selected_credentials; + + selected_credentials } pub async fn exchange_proof( @@ -441,7 +440,7 @@ pub async fn exchange_proof( request_name: Option<&str>, ) -> Verifier { let mut verifier = - verifier_create_proof_and_send_request(institution, &schema_id, &cred_def_id, request_name) + verifier_create_proof_and_send_request(institution, schema_id, cred_def_id, request_name) .await; let presentation = prover_select_credentials_and_send_proof( consumer,