From 50113d0d6be8c0568648289884be6b10c3082402 Mon Sep 17 00:00:00 2001 From: lli Date: Mon, 18 Dec 2023 13:38:44 -0800 Subject: [PATCH] lli - move custom engine to utils Signed-off-by: lli --- aries/aries_vcx/src/common/signing.rs | 17 ++--------------- aries/aries_vcx/src/utils/base64.rs | 13 +++++++++++++ aries/aries_vcx/src/utils/mod.rs | 1 + 3 files changed, 16 insertions(+), 15 deletions(-) create mode 100644 aries/aries_vcx/src/utils/base64.rs diff --git a/aries/aries_vcx/src/common/signing.rs b/aries/aries_vcx/src/common/signing.rs index f938bdc875..acca48c4c9 100644 --- a/aries/aries_vcx/src/common/signing.rs +++ b/aries/aries_vcx/src/common/signing.rs @@ -1,25 +1,12 @@ use aries_vcx_core::wallet::base_wallet::BaseWallet; -use base64::{ - self, alphabet, - engine::{general_purpose, DecodePaddingMode, GeneralPurpose, GeneralPurposeConfig}, - Engine, -}; +use base64::{self, engine::general_purpose, Engine}; use messages::msg_fields::protocols::connection::{ response::{ConnectionSignature, ResponseContent}, ConnectionData, }; use time; -use crate::errors::error::prelude::*; - -/// A default [GeneralPurposeConfig] configuration with a [decode_padding_mode] of -/// [DecodePaddingMode::Indifferent] -pub const LENIENT_PAD: GeneralPurposeConfig = - GeneralPurposeConfig::new().with_decode_padding_mode(DecodePaddingMode::Indifferent); - -/// A [GeneralPurpose] engine using the [alphabet::URL_SAFE] base64 alphabet and -/// [DecodePaddingMode::Indifferent] config to decode both padded and unpadded. -pub const URL_SAFE_LENIENT: GeneralPurpose = GeneralPurpose::new(&alphabet::URL_SAFE, LENIENT_PAD); +use crate::{errors::error::prelude::*, utils::base64::URL_SAFE_LENIENT}; // Utility function to handle both padded and unpadded Base64URL data fn base64url_decode(encoded: &str) -> VcxResult> { diff --git a/aries/aries_vcx/src/utils/base64.rs b/aries/aries_vcx/src/utils/base64.rs new file mode 100644 index 0000000000..5ce3dbc711 --- /dev/null +++ b/aries/aries_vcx/src/utils/base64.rs @@ -0,0 +1,13 @@ +use base64::{ + alphabet, + engine::{DecodePaddingMode, GeneralPurpose, GeneralPurposeConfig}, +}; + +/// A default [GeneralPurposeConfig] configuration with a [decode_padding_mode] of +/// [DecodePaddingMode::Indifferent] +pub const LENIENT_PAD: GeneralPurposeConfig = + GeneralPurposeConfig::new().with_decode_padding_mode(DecodePaddingMode::Indifferent); + +/// A [GeneralPurpose] engine using the [alphabet::URL_SAFE] base64 alphabet and +/// [DecodePaddingMode::Indifferent] config to decode both padded and unpadded. +pub const URL_SAFE_LENIENT: GeneralPurpose = GeneralPurpose::new(&alphabet::URL_SAFE, LENIENT_PAD); diff --git a/aries/aries_vcx/src/utils/mod.rs b/aries/aries_vcx/src/utils/mod.rs index a4cdd20271..7fb33cb1eb 100644 --- a/aries/aries_vcx/src/utils/mod.rs +++ b/aries/aries_vcx/src/utils/mod.rs @@ -26,6 +26,7 @@ macro_rules! secret { }}; } +pub mod base64; pub mod openssl; pub mod qualifier;