From 7c4d90f829ed2b910571e568e4ca11394ce72e03 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Thu, 21 Dec 2023 10:20:44 +0300 Subject: [PATCH] Fixed merge errors Signed-off-by: artem.ivanov --- src/data_types/w3c/proof.rs | 5 +++-- src/services/w3c/credential_conversion.rs | 4 ++-- src/services/w3c/prover.rs | 6 +++--- src/utils/base64.rs | 4 ++-- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/data_types/w3c/proof.rs b/src/data_types/w3c/proof.rs index bb3e977b..14bd0df4 100644 --- a/src/data_types/w3c/proof.rs +++ b/src/data_types/w3c/proof.rs @@ -195,13 +195,13 @@ pub struct CredentialProofDetails { const BASE_HEADER: char = 'u'; pub trait EncodedObject { - fn encode(&self) -> String + fn encode(&self) -> Result where Self: Serialize, { let bytes = msg_pack::encode(self)?; let base64_encoded = base64::encode(bytes); - format!("{}{}", BASE_HEADER, base64_encoded) + Ok(format!("{}{}", BASE_HEADER, base64_encoded)) } fn decode(string: &str) -> Result @@ -239,6 +239,7 @@ mod tests { value: 1, }; let encoded = obj.encode().unwrap(); + assert_eq!("ugqV0eXBlX6RUZXN0pXZhbHVlAQ", encoded); let decoded = TestObject::decode(&encoded).unwrap(); assert_eq!(obj, decoded) } diff --git a/src/services/w3c/credential_conversion.rs b/src/services/w3c/credential_conversion.rs index 9890fe18..fb698a43 100644 --- a/src/services/w3c/credential_conversion.rs +++ b/src/services/w3c/credential_conversion.rs @@ -110,7 +110,7 @@ pub fn credential_to_w3c( rev_reg: credential.rev_reg, witness: credential.witness, }; - let proof = DataIntegrityProof::new_credential_proof(signature); + let proof = DataIntegrityProof::new_credential_proof(signature)?; let w3c_credential = W3CCredential::new(issuer, attributes, proof, version.as_ref()); trace!("credential_to_w3c <<< w3c_credential {:?}", w3c_credential); @@ -347,7 +347,7 @@ pub(super) mod tests { W3CCredential::new( issuer_id(), CredentialAttributes::from(&cred_values()), - DataIntegrityProof::new_credential_proof(_signature_data()), + DataIntegrityProof::new_credential_proof(_signature_data()).unwrap(), None, ) } diff --git a/src/services/w3c/prover.rs b/src/services/w3c/prover.rs index 344fa072..812005ca 100644 --- a/src/services/w3c/prover.rs +++ b/src/services/w3c/prover.rs @@ -119,7 +119,7 @@ pub fn process_credential( credential_signature.witness.as_ref(), )?; - *proof = DataIntegrityProof::new_credential_proof(credential_signature); + *proof = DataIntegrityProof::new_credential_proof(credential_signature)?; trace!("process_w3c_credential <<< "); @@ -192,7 +192,7 @@ pub fn create_presentation( timestamp: present.timestamp, sub_proof, }; - let proof = DataIntegrityProof::new_credential_presentation_proof(proof); + let proof = DataIntegrityProof::new_credential_presentation_proof(proof)?; let credential = W3CCredential::derive(credential_attributes, proof, present.cred); verifiable_credentials.push(credential); } @@ -203,7 +203,7 @@ pub fn create_presentation( let proof = DataIntegrityProof::new_presentation_proof( presentation_proof, presentation_request.nonce.to_string(), - ); + )?; let presentation = W3CPresentation::new(verifiable_credentials, proof, version.as_ref()); trace!( diff --git a/src/utils/base64.rs b/src/utils/base64.rs index f3507352..457d3daf 100644 --- a/src/utils/base64.rs +++ b/src/utils/base64.rs @@ -3,11 +3,11 @@ use base64::{engine, Engine}; use crate::Error; pub fn encode>(val: T) -> String { - engine::general_purpose::URL_SAFE.encode(val) + engine::general_purpose::URL_SAFE_NO_PAD.encode(val) } pub fn decode>(val: T) -> Result, Error> { - engine::general_purpose::URL_SAFE + engine::general_purpose::URL_SAFE_NO_PAD .decode(val) .map_err(|_| err_msg!("invalid base64 string")) }