Skip to content

Commit

Permalink
Fixed merge errors
Browse files Browse the repository at this point in the history
Signed-off-by: artem.ivanov <artem.ivanov@dsr-corporation.com>
  • Loading branch information
Artemkaaas committed Dec 21, 2023
1 parent 1c69a69 commit 7c4d90f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
5 changes: 3 additions & 2 deletions src/data_types/w3c/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,13 @@ pub struct CredentialProofDetails {
const BASE_HEADER: char = 'u';

pub trait EncodedObject {
fn encode(&self) -> String
fn encode(&self) -> Result<String>
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<Self>
Expand Down Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions src/services/w3c/credential_conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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,
)
}
Expand Down
6 changes: 3 additions & 3 deletions src/services/w3c/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 <<< ");

Expand Down Expand Up @@ -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);
}
Expand All @@ -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!(
Expand Down
4 changes: 2 additions & 2 deletions src/utils/base64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ use base64::{engine, Engine};
use crate::Error;

pub fn encode<T: AsRef<[u8]>>(val: T) -> String {
engine::general_purpose::URL_SAFE.encode(val)
engine::general_purpose::URL_SAFE_NO_PAD.encode(val)
}

pub fn decode<T: AsRef<[u8]>>(val: T) -> Result<Vec<u8>, Error> {
engine::general_purpose::URL_SAFE
engine::general_purpose::URL_SAFE_NO_PAD
.decode(val)
.map_err(|_| err_msg!("invalid base64 string"))
}

0 comments on commit 7c4d90f

Please sign in to comment.