Skip to content

Commit

Permalink
Macro formatting fix
Browse files Browse the repository at this point in the history
Signed-off-by: Bogdan Mircea <mirceapetrebogdan@gmail.com>
  • Loading branch information
bobozaur committed Sep 20, 2023
1 parent 5a38524 commit 339bb1b
Showing 1 changed file with 12 additions and 29 deletions.
41 changes: 12 additions & 29 deletions aries_vcx/src/handlers/util.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use messages::{
decorators::attachment::Attachment,
msg_fields::protocols::{
connection::{invitation::Invitation, Connection},
cred_issuance::CredentialIssuance,
Expand Down Expand Up @@ -34,38 +35,20 @@ macro_rules! matches_opt_thread_id {
};
}

#[rustfmt::skip] // This macro results in some false positives and formatting makes it harder to read
macro_rules! get_attach_as_string {
($attachments:expr) => {{
let __attach = $attachments.get(0).as_ref().map(|a| &a.data.content);
let Some(messages::decorators::attachment::AttachmentType::Base64(encoded_attach)) =
__attach
else {
return Err(AriesVcxError::from_msg(
AriesVcxErrorKind::SerializationError,
format!(
"Attachment is not base 64 encoded JSON: {:?}",
$attachments.get(0)
),
));
};
let Ok(bytes) = base64::decode(encoded_attach) else {
return Err(AriesVcxError::from_msg(
AriesVcxErrorKind::SerializationError,
format!(
"Attachment is not base 64 encoded JSON: {:?}",
$attachments.get(0)
),
));
};
let Ok(attach_string) = String::from_utf8(bytes) else {
return Err(AriesVcxError::from_msg(
AriesVcxErrorKind::SerializationError,
format!(
"Attachment is not base 64 encoded JSON: {:?}",
$attachments.get(0)
),
));
};
let err_fn = |attach: Option<&messages::decorators::attachment::Attachment>| {
Err(AriesVcxError::from_msg(
AriesVcxErrorKind::SerializationError,
format!("Attachment is not base 64 encoded JSON: {:?}", attach),
))
};

let Some(messages::decorators::attachment::AttachmentType::Base64(encoded_attach)) = __attach else { return err_fn($attachments.get(0)); };
let Ok(bytes) = base64::decode(encoded_attach) else { return err_fn($attachments.get(0)); };
let Ok(attach_string) = String::from_utf8(bytes) else { return err_fn($attachments.get(0)); };

attach_string
}};
Expand Down

0 comments on commit 339bb1b

Please sign in to comment.