Skip to content

Commit

Permalink
[FIX] Reduce unnecessary required deps (#1217)
Browse files Browse the repository at this point in the history
* updates

Signed-off-by: George Mulhearn <gmulhearn@anonyome.com>

* fmt

Signed-off-by: George Mulhearn <gmulhearn@anonyome.com>

* small patch

Signed-off-by: George Mulhearn <gmulhearn@anonyome.com>

* undo base64 update

Signed-off-by: George Mulhearn <gmulhearn@anonyome.com>

---------

Signed-off-by: George Mulhearn <gmulhearn@anonyome.com>
  • Loading branch information
gmulhearn-anonyome authored Jun 6, 2024
1 parent ca35f08 commit d6bfca9
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion aries/aries_vcx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ did_doc = { path = "../../did_core/did_doc" }
did_key = { path = "../../did_core/did_methods/did_key" }
public_key = { path = "../../did_core/public_key" }
did_peer = { path = "../../did_core/did_methods/did_peer" }
did_resolver_sov = { path = "../../did_core/did_methods/did_resolver_sov" }
did_resolver_registry = { path = "../../did_core/did_resolver_registry" }
bs58 = "0.5.0"
async-trait = "0.1.53"
Expand Down Expand Up @@ -83,3 +82,4 @@ wallet_migrator = { path = "../misc/wallet_migrator" }
async-channel = "1.7.1"
tokio = { version = "1.20", features = ["rt", "macros", "rt-multi-thread"] }
pretty_assertions = "1.4.0"
did_resolver_sov = { path = "../../did_core/did_methods/did_resolver_sov" }
17 changes: 14 additions & 3 deletions aries/aries_vcx/src/errors/mapping_wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ impl From<VcxWalletError> for AriesVcxError {
VcxWalletError::UnknownRecordCategory(_) => {
Self::from_msg(AriesVcxErrorKind::InvalidInput, value.to_string())
}
VcxWalletError::IndyApiError(_) => {
Self::from_msg(AriesVcxErrorKind::InvalidLedgerResponse, value.to_string())
}
VcxWalletError::InvalidInput(_) => {
Self::from_msg(AriesVcxErrorKind::InvalidInput, value.to_string())
}
Expand Down Expand Up @@ -48,6 +45,20 @@ impl From<VcxWalletError> for AriesVcxError {
VcxWalletError::NotBase64(_) => {
Self::from_msg(AriesVcxErrorKind::ParsingError, value.to_string())
}
// imperfect solution:
// ideally we want this to be conditionally compiled if the
// aries_vcx_wallet/vdrtools_wallet feature is enabled, rather than the
// aries_vcx/vdrtools_wallet feature. however that is not possible currently
// with cargo. as such, if we have a case where
// aries_vcx_wallet/vdrtool_wallet is enabled, but aries_vcx/vdrtools_wallet
// is not, then the error will fall thru to the catch all case `_ =>`
#[cfg(feature = "vdrtools_wallet")]
VcxWalletError::IndyApiError(_) => {
Self::from_msg(AriesVcxErrorKind::InvalidLedgerResponse, value.to_string())
}
// can be
#[allow(unreachable_patterns)]
_ => Self::from_msg(AriesVcxErrorKind::UnknownError, value.to_string()),
}
}
}
5 changes: 1 addition & 4 deletions aries/aries_vcx_anoncreds/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,14 @@ edition.workspace = true

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[features]
default =["credx", "vdrtools_wallet"]
credx = ["dep:indy-credx"]
anoncreds = ["dep:anoncreds"]
legacy_proof = []
vdrtools_wallet = ["aries_vcx_wallet/vdrtools_wallet"]
askar_wallet = ["aries_vcx_wallet/askar_wallet"]

[dependencies]
indy-credx = { git = "https://github.com/hyperledger/indy-shared-rs", tag = "v1.1.0", optional = true }
aries_vcx_wallet = { path = "../aries_vcx_wallet" }
anoncreds = { git = "https://github.com/hyperledger/anoncreds-rs.git", tag = "v0.2.0", optional = true }
aries_vcx_wallet = { path = "../aries_vcx_wallet" }
anoncreds_types = { path = "../misc/anoncreds_types" }
did_parser_nom = { path = "../../did_core/did_parser_nom" }
async-trait = "0.1.68"
Expand Down
2 changes: 1 addition & 1 deletion aries/aries_vcx_wallet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ anyhow = "1.0"
aries-askar = { version = "=0.3.0", optional = true }
async-trait = "0.1.68"
bs58 = { version = "0.5" }
base64 = "0.21"
libvdrtools = { path = "../misc/legacy/libvdrtools", optional = true }
log = "0.4.17"
indy-api-types = { path = "../misc/legacy/libvdrtools/indy-api-types", optional = true }
indy-vdr = { git = "https://github.com/hyperledger/indy-vdr.git", rev = "c143268", default-features = false, features = ["log"] }
serde = { version = "1.0.159", features = ["derive"] }
serde_json = "1.0.95"
public_key = { path = "../../did_core/public_key"}
Expand Down
3 changes: 1 addition & 2 deletions aries/aries_vcx_wallet/src/errors/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use std::{
string::FromUtf8Error,
};

use indy_vdr::utils::ConversionError;
use thiserror::Error as ThisError;
#[cfg(feature = "vdrtools_wallet")]
use vdrtools::IndyError;
Expand Down Expand Up @@ -51,7 +50,7 @@ pub enum VcxWalletError {
DuplicateRecord(String),
NotUtf8(FromUtf8Error),
NotBase58(bs58::decode::Error),
NotBase64(ConversionError),
NotBase64(base64::DecodeError),
RecordNotFound(NotFoundInfo),
UnknownRecordCategory(String),
#[cfg(feature = "vdrtools_wallet")]
Expand Down
6 changes: 2 additions & 4 deletions aries/aries_vcx_wallet/src/errors/mapping_others.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use std::string::FromUtf8Error;

use indy_vdr::utils::ConversionError;

use super::error::VcxWalletError;

impl From<bs58::decode::Error> for VcxWalletError {
Expand All @@ -10,8 +8,8 @@ impl From<bs58::decode::Error> for VcxWalletError {
}
}

impl From<ConversionError> for VcxWalletError {
fn from(value: ConversionError) -> Self {
impl From<base64::DecodeError> for VcxWalletError {
fn from(value: base64::DecodeError) -> Self {
Self::NotBase64(value)
}
}
Expand Down
20 changes: 17 additions & 3 deletions aries/aries_vcx_wallet/src/wallet/base_wallet/base64_string.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,33 @@
use indy_vdr::utils::base64::{decode_urlsafe, encode_urlsafe};
use base64::{
alphabet,
engine::{DecodePaddingMode, GeneralPurpose, GeneralPurposeConfig},
Engine,
};
use serde::{Deserialize, Serialize};

use crate::{errors::error::VcxWalletResult, wallet::utils::bytes_to_string};

/// A default [GeneralPurposeConfig] configuration with a [decode_padding_mode] of
/// [DecodePaddingMode::Indifferent]
const LENIENT_PAD: GeneralPurposeConfig = GeneralPurposeConfig::new()
.with_encode_padding(false)
.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.
const URL_SAFE_LENIENT: GeneralPurpose = GeneralPurpose::new(&alphabet::URL_SAFE, LENIENT_PAD);

#[derive(Serialize, Deserialize, Debug)]
#[serde(transparent)]
pub struct Base64String(String);

impl Base64String {
pub fn from_bytes(content: &[u8]) -> Self {
Self(encode_urlsafe(content))
Self(URL_SAFE_LENIENT.encode(content))
}

pub fn decode(&self) -> VcxWalletResult<Vec<u8>> {
Ok(decode_urlsafe(&self.0)?)
Ok(URL_SAFE_LENIENT.decode(&self.0)?)
}

pub fn decode_to_string(&self) -> VcxWalletResult<String> {
Expand Down
2 changes: 1 addition & 1 deletion aries/misc/legacy/libvdrtools/indy-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ hash_openssl = []
randombytes_sodium = []

[dependencies]
base64 = {version = "0.21"}
base64 = {version = "0.21.2"}
dirs = "5"
failure = "0.1"
indy-api-types = { path = "../indy-api-types" }
Expand Down
2 changes: 1 addition & 1 deletion did_core/did_methods/did_resolver_sov/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ edition = "2021"

[dependencies]
did_resolver = { path = "../../did_resolver" }
aries_vcx_wallet = { path = "../../../aries/aries_vcx_wallet" }
aries_vcx_ledger = { path = "../../../aries/aries_vcx_ledger" }
async-trait = "0.1.68"
mockall = "0.11.4"
Expand All @@ -21,3 +20,4 @@ aries_vcx = { path = "../../../aries/aries_vcx" }
tokio = { version = "1.27.0", default-features = false, features = ["macros", "rt"] }
uuid = "1.3.1"
test_utils = {path = "../../../aries/misc/test_utils", features = ["vdrtools_wallet"] }
aries_vcx_wallet = { path = "../../../aries/aries_vcx_wallet" }

0 comments on commit d6bfca9

Please sign in to comment.