diff --git a/src/data_types/w3c/credential.rs b/src/data_types/w3c/credential.rs index da10c65e..e04c9d75 100644 --- a/src/data_types/w3c/credential.rs +++ b/src/data_types/w3c/credential.rs @@ -2,6 +2,7 @@ use chrono::{DateTime, Utc}; use serde::{de, Deserialize, Deserializer, Serialize, Serializer}; use serde_json::Value; use std::collections::{HashMap, HashSet}; +use std::fmt::{Display, Formatter}; use std::string::ToString; use zeroize::Zeroize; @@ -201,13 +202,13 @@ pub enum CredentialStatusType { Other(String), } -impl ToString for CredentialStatusType { - fn to_string(&self) -> String { +impl Display for CredentialStatusType { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { match self { CredentialStatusType::AnonCredsCredentialStatusList2023 => { - "AnonCredsCredentialStatusList2023".to_string() + f.write_str("AnonCredsCredentialStatusList2023") } - CredentialStatusType::Other(other) => other.to_string(), + CredentialStatusType::Other(other) => f.write_str(other), } } } diff --git a/src/data_types/w3c/presentation_proof.rs b/src/data_types/w3c/presentation_proof.rs index 5105fb73..a1fb3e5c 100644 --- a/src/data_types/w3c/presentation_proof.rs +++ b/src/data_types/w3c/presentation_proof.rs @@ -9,7 +9,6 @@ use std::collections::HashSet; pub struct CredentialPresentationProof { #[serde(rename = "type")] pub type_: PresentationProofType, - /// Uniform Resource Identifier - https://www.w3.org/TR/vc-data-model/#dfn-uri // FIXME: Consider either removing or moving under proof_value // In fact, it's only needed to make attributes validation on the verifier side // Revealed attributes and predicates can be restored from credential subject, but not unrevealed attributes diff --git a/src/services/helpers.rs b/src/services/helpers.rs index 244a729c..59bb6d66 100644 --- a/src/services/helpers.rs +++ b/src/services/helpers.rs @@ -251,7 +251,7 @@ pub fn get_non_revoked_interval( impl RequestedProof { // get list of revealed attributes per credential - pub(crate) fn attribute_referents(&self, index: u32) -> HashSet { + pub(crate) fn get_attribute_referents(&self, index: u32) -> HashSet { let mut referents = HashSet::new(); for (referent, into) in self.revealed_attrs.iter() { if into.sub_proof_index == index { @@ -267,7 +267,7 @@ impl RequestedProof { } // get list of revealed predicates per credential - pub(crate) fn predicate_referents(&self, index: u32) -> HashSet { + pub(crate) fn get_predicate_referents(&self, index: u32) -> HashSet { let mut referents = HashSet::new(); for (referent, info) in self.predicates.iter() { if info.sub_proof_index == index { diff --git a/src/services/issuer.rs b/src/services/issuer.rs index c414d36e..44e1cf61 100644 --- a/src/services/issuer.rs +++ b/src/services/issuer.rs @@ -714,7 +714,7 @@ pub fn create_credential( ); let (credential_signature, signature_correctness_proof, rev_reg_id, rev_reg, witness) = - CLCredentialIssuer::init(cred_def, cred_def_private)?.create_credential( + CLCredentialIssuer::new(cred_def, cred_def_private).create_credential( cred_offer, cred_request, &cred_values, @@ -746,14 +746,14 @@ pub(crate) struct CLCredentialIssuer<'a> { } impl<'a> CLCredentialIssuer<'a> { - pub(crate) fn init( + pub(crate) fn new( cred_def: &'a CredentialDefinition, cred_def_private: &'a CredentialDefinitionPrivate, - ) -> Result> { - Ok(CLCredentialIssuer { + ) -> CLCredentialIssuer<'a> { + CLCredentialIssuer { cred_def, cred_def_private, - }) + } } #[allow(clippy::type_complexity)] diff --git a/src/services/prover.rs b/src/services/prover.rs index 8a09a4a4..61cbb737 100644 --- a/src/services/prover.rs +++ b/src/services/prover.rs @@ -252,7 +252,7 @@ pub fn process_credential( trace!("process_credential >>> credential: {:?}, cred_request_metadata: {:?}, link_secret: {:?}, cred_def: {:?}, rev_reg_def: {:?}", credential, cred_request_metadata, secret!(&link_secret), cred_def, rev_reg_def); - CLCredentialProver::init(link_secret)?.process_credential( + CLCredentialProver::new(link_secret).process_credential( &mut credential.signature, &credential.signature_correctness_proof, &credential.values, @@ -417,7 +417,7 @@ pub fn create_presentation( let mut sub_proof_index = 0; let mut identifiers: Vec = Vec::with_capacity(credentials.len()); - let mut proof_builder = CLProofBuilder::init(pres_req_val, schemas, cred_defs)?; + let mut proof_builder = CLProofBuilder::new(pres_req_val, schemas, cred_defs)?; for present in credentials.0 { if present.is_empty() { @@ -770,8 +770,8 @@ pub(crate) struct CLCredentialProver<'a> { } impl<'a> CLCredentialProver<'a> { - pub(crate) fn init(link_secret: &'a LinkSecret) -> Result> { - Ok(CLCredentialProver { link_secret }) + pub(crate) fn new(link_secret: &'a LinkSecret) -> CLCredentialProver<'a> { + CLCredentialProver { link_secret } } #[allow(clippy::too_many_arguments)] @@ -821,7 +821,7 @@ pub(crate) struct CLProofBuilder<'a> { } impl<'a> CLProofBuilder<'a> { - pub(crate) fn init( + pub(crate) fn new( presentation_request: &'a PresentationRequestPayload, schemas: &'a HashMap, cred_defs: &'a HashMap, @@ -862,7 +862,7 @@ impl<'a> CLProofBuilder<'a> { let (attrs_for_credential, attrs_nonrevoked_interval) = self .presentation_request - .get_requested_attributes(&present.requested_attributes())?; + .get_requested_attributes(&present.revealed_attributes())?; let (predicates_for_credential, pred_nonrevoked_interval) = self .presentation_request .get_requested_predicates(&present.requested_predicates)?; @@ -936,8 +936,6 @@ impl<'a> CLProofBuilder<'a> { mod tests { use super::*; - // use crate::data_types::pres_request::PredicateTypes; - macro_rules! hashmap { ($( $key: expr => $val: expr ),*) => { { diff --git a/src/services/types.rs b/src/services/types.rs index 53148c26..510eb0ec 100644 --- a/src/services/types.rs +++ b/src/services/types.rs @@ -161,7 +161,7 @@ impl PresentCredential<'_, T> { self.requested_attributes.is_empty() && self.requested_predicates.is_empty() } - pub(crate) fn requested_attributes(&self) -> HashSet { + pub(crate) fn revealed_attributes(&self) -> HashSet { let mut referents = HashSet::new(); for (referent, revealed) in self.requested_attributes.iter() { if *revealed { diff --git a/src/services/verifier.rs b/src/services/verifier.rs index 11ca11cd..7332eee4 100644 --- a/src/services/verifier.rs +++ b/src/services/verifier.rs @@ -89,7 +89,7 @@ pub fn verify_presentation( &received_self_attested_attrs, )?; - let mut proof_verifier = CLProofVerifier::init( + let mut proof_verifier = CLProofVerifier::new( pres_req, schemas, cred_defs, @@ -102,10 +102,10 @@ pub fn verify_presentation( let attributes = presentation .requested_proof - .attribute_referents(sub_proof_index as u32); + .get_attribute_referents(sub_proof_index as u32); let predicates = presentation .requested_proof - .predicate_referents(sub_proof_index as u32); + .get_predicate_referents(sub_proof_index as u32); proof_verifier.add_sub_proof( &attributes, @@ -760,7 +760,7 @@ pub(crate) struct CLProofVerifier<'a> { } impl<'a> CLProofVerifier<'a> { - pub(crate) fn init( + pub(crate) fn new( presentation_request: &'a PresentationRequestPayload, schemas: &'a HashMap, cred_defs: &'a HashMap, diff --git a/src/services/w3c/helpers.rs b/src/services/w3c/helpers.rs index 974e966e..78b8a028 100644 --- a/src/services/w3c/helpers.rs +++ b/src/services/w3c/helpers.rs @@ -18,7 +18,7 @@ impl W3CCredential { .ok_or_else(|| err_msg!("Credential attribute {} not found", requested_attribute)) } - pub(crate) fn attributes(&self) -> HashMap { + pub(crate) fn get_attributes(&self) -> HashMap { let mut attributes: HashMap = HashMap::new(); for (name, attribute) in self.credential_subject.attributes.0.iter() { if let CredentialAttributeValue::Attribute(attribute) = attribute { diff --git a/src/services/w3c/issuer.rs b/src/services/w3c/issuer.rs index d63409aa..bca88f52 100644 --- a/src/services/w3c/issuer.rs +++ b/src/services/w3c/issuer.rs @@ -100,7 +100,7 @@ pub fn create_credential( let credential_values = raw_credential_values.encode(&encoding)?; let (credential_signature, signature_correctness_proof, rev_reg_id, rev_reg, witness) = - CLCredentialIssuer::init(cred_def, cred_def_private)?.create_credential( + CLCredentialIssuer::new(cred_def, cred_def_private).create_credential( cred_offer, cred_request, &credential_values, diff --git a/src/services/w3c/prover.rs b/src/services/w3c/prover.rs index f9d60947..e0fd3791 100644 --- a/src/services/w3c/prover.rs +++ b/src/services/w3c/prover.rs @@ -109,7 +109,7 @@ pub fn process_credential( let proof = w3c_credential.get_mut_credential_signature_proof()?; let mut signature = proof.get_credential_signature()?; - CLCredentialProver::init(link_secret)?.process_credential( + CLCredentialProver::new(link_secret).process_credential( &mut signature.signature, &signature.signature_correctness_proof, &cred_values, @@ -152,7 +152,7 @@ pub fn create_presentation( let pres_req = pres_req.value(); - let mut proof_builder = CLProofBuilder::init(pres_req, schemas, cred_defs)?; + let mut proof_builder = CLProofBuilder::new(pres_req, schemas, cred_defs)?; for present in credentials.0.iter() { if present.is_empty() { diff --git a/src/services/w3c/verifier.rs b/src/services/w3c/verifier.rs index 28326545..e129adbc 100644 --- a/src/services/w3c/verifier.rs +++ b/src/services/w3c/verifier.rs @@ -73,7 +73,7 @@ pub fn verify_presentation( aggregated_proof: proof_data.aggregated, }; - let mut proof_verifier = CLProofVerifier::init( + let mut proof_verifier = CLProofVerifier::new( pres_req, schemas, cred_defs, @@ -233,7 +233,7 @@ fn _check_encoded_attributes( credential_proof: &CredentialPresentationProofValue, ) -> Result<()> { credential - .attributes() + .get_attributes() .iter() .map(|(name, value)| { encode_credential_attribute(value).and_then(|encoded| {