Skip to content

Commit

Permalink
Fix lints in aries_vcx (#989)
Browse files Browse the repository at this point in the history
Addressed lints and formatting in aries_vcx.

Signed-off-by: Bogdan Mircea <mirceapetrebogdan@gmail.com>
  • Loading branch information
bobozaur authored Sep 21, 2023
1 parent 4b6c15b commit b25d388
Show file tree
Hide file tree
Showing 30 changed files with 162 additions and 235 deletions.
2 changes: 1 addition & 1 deletion aries_vcx/src/common/anoncreds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub mod integration_tests {
let proof_req = "{";
let anoncreds = Arc::clone(&setup.profile).inject_anoncreds();
let result = anoncreds
.prover_get_credentials_for_proof_req(&proof_req)
.prover_get_credentials_for_proof_req(proof_req)
.await;
assert_eq!(
result.unwrap_err().kind(),
Expand Down
16 changes: 7 additions & 9 deletions aries_vcx/src/common/ledger/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,8 @@ pub async fn into_did_doc(
let mut did_doc: AriesDidDoc = AriesDidDoc::default();
let (service_endpoint, recipient_keys, routing_keys) = match invitation {
AnyInvitation::Con(Invitation {
id,
content: InvitationContent::Public(content),
decorators,
..
}) => {
did_doc.set_id(content.did.to_string());
let service = get_service(indy_ledger, &content.did)
Expand All @@ -130,7 +129,7 @@ pub async fn into_did_doc(
AnyInvitation::Con(Invitation {
id,
content: InvitationContent::Pairwise(content),
decorators,
..
}) => {
did_doc.set_id(id.clone());
(
Expand All @@ -140,13 +139,12 @@ pub async fn into_did_doc(
)
}
AnyInvitation::Con(Invitation {
id,
content: InvitationContent::PairwiseDID(content),
decorators,
content: InvitationContent::PairwiseDID(_content),
..
}) => {
return Err(AriesVcxError::from_msg(
AriesVcxErrorKind::InvalidDid,
format!("PairwiseDID invitation not supported yet!"),
"PairwiseDID invitation not supported yet!",
))
}
AnyInvitation::Oob(invitation) => {
Expand Down Expand Up @@ -336,7 +334,7 @@ pub async fn add_attr(
did: &str,
attr: &str,
) -> VcxResult<()> {
let res = indy_ledger_write.add_attr(did, &attr).await?;
let res = indy_ledger_write.add_attr(did, attr).await?;
check_response(&res)
}

Expand Down Expand Up @@ -365,7 +363,7 @@ pub async fn clear_attr(
.map_err(|err| err.into())
}

pub(self) fn check_response(response: &str) -> VcxResult<()> {
fn check_response(response: &str) -> VcxResult<()> {
if settings::indy_mocks_enabled() {
return Ok(());
}
Expand Down
88 changes: 30 additions & 58 deletions aries_vcx/src/common/primitives/credential_definition.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{fmt, sync::Arc};
use std::sync::Arc;

use aries_vcx_core::{
anoncreds::base_anoncreds::BaseAnonCreds,
Expand All @@ -15,62 +15,40 @@ use crate::{
},
};

macro_rules! enum_number {
($name:ident { $($variant:ident = $value:expr, )* }) => {
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum $name {
$($variant = $value,)*
}
#[derive(Clone, Copy, Debug, Eq, PartialEq, Deserialize, Default)]
#[serde(try_from = "u8")]
#[repr(u8)]
pub enum PublicEntityStateType {
Built = 0,
#[default]
Published = 1,
}

impl ::serde::Serialize for $name {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: ::serde::Serializer
{
// Serialize the enum as a u64.
serializer.serialize_u64(*self as u64)
}
}
impl ::serde::Serialize for PublicEntityStateType {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: ::serde::Serializer,
{
serializer.serialize_u8(*self as u8)
}
}

impl<'de> ::serde::Deserialize<'de> for $name {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: ::serde::Deserializer<'de>
{
struct Visitor;

impl<'de> ::serde::de::Visitor<'de> for Visitor {
type Value = $name;

fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter.write_str("positive integer")
}

fn visit_u64<E>(self, value: u64) -> Result<$name, E>
where E: ::serde::de::Error
{
// Rust does not come with a simple way of converting a
// number to an enum, so use a big `match`.
match value {
$( $value => Ok($name::$variant), )*
_ => Err(E::custom(
format!("unknown {} value: {}",
stringify!($name), value))),
}
}
}

// Deserialize the enum from a u64.
deserializer.deserialize_u64(Visitor)
}
impl TryFrom<u8> for PublicEntityStateType {
type Error = String;

fn try_from(value: u8) -> Result<Self, Self::Error> {
match value {
0 => Ok(PublicEntityStateType::Built),
1 => Ok(PublicEntityStateType::Published),
_ => Err(format!(
"unknown {} value: {}",
stringify!(PublicEntityStateType),
value
)),
}
}
}

enum_number!(PublicEntityStateType
{
Built = 0,
Published = 1,
});

#[derive(Clone, Deserialize, Debug, Serialize, PartialEq, Eq, Default)]
pub struct CredentialDef {
#[serde(alias = "cred_def_id")]
Expand Down Expand Up @@ -102,12 +80,6 @@ pub struct RevocationDetails {
pub max_creds: Option<u32>,
}

impl Default for PublicEntityStateType {
fn default() -> Self {
PublicEntityStateType::Published
}
}

async fn _try_get_cred_def_from_ledger(
ledger: &Arc<dyn AnoncredsLedgerRead>,
issuer_did: &str,
Expand Down Expand Up @@ -193,7 +165,7 @@ impl CredentialDef {
self.id
);
if let Some(ledger_cred_def_json) =
_try_get_cred_def_from_ledger(&ledger_read, &self.issuer_did, &self.id).await?
_try_get_cred_def_from_ledger(ledger_read, &self.issuer_did, &self.id).await?
{
return Err(AriesVcxError::from_msg(
AriesVcxErrorKind::CredDefAlreadyCreated,
Expand Down
6 changes: 1 addition & 5 deletions aries_vcx/src/common/primitives/revocation_registry_delta.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
use std::sync::Arc;

use aries_vcx_core::ledger::base_ledger::AnoncredsLedgerRead;

use crate::errors::error::prelude::*;

#[derive(Clone, Deserialize, Debug, Serialize, Default)]
Expand Down Expand Up @@ -34,7 +30,7 @@ impl RevocationRegistryDeltaValue {

impl RevocationRegistryDelta {
pub async fn create_from_ledger(rev_reg_delta_json: &str) -> VcxResult<Self> {
serde_json::from_str(&rev_reg_delta_json).map_err(|err| {
serde_json::from_str(rev_reg_delta_json).map_err(|err| {
AriesVcxError::from_msg(
AriesVcxErrorKind::SerializationError,
format!(
Expand Down
4 changes: 2 additions & 2 deletions aries_vcx/src/common/proofs/proof_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ mod unit_tests {
let request = ProofRequestData::create(&anoncreds, "")
.await
.unwrap()
.set_requested_attributes_as_string(requested_attrs.into())
.set_requested_attributes_as_string(requested_attrs)
.unwrap();

let mut expected_req_attrs: HashMap<String, AttrInfo> = HashMap::new();
Expand Down Expand Up @@ -359,7 +359,7 @@ mod unit_tests {
let err = ProofRequestData::create(&anoncreds, "")
.await
.unwrap()
.set_requested_attributes_as_string(requested_attrs.into())
.set_requested_attributes_as_string(requested_attrs)
.unwrap_err();

assert_eq!(AriesVcxErrorKind::InvalidProofRequest, err.kind());
Expand Down
29 changes: 13 additions & 16 deletions aries_vcx/src/common/proofs/prover/prover_internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ pub fn credential_def_identifiers(
credential_referent: cred_info.referent.clone(),
schema_id: cred_info.schema_id.clone(),
cred_def_id: cred_info.cred_def_id.clone(),
revocation_interval: _get_revocation_interval(&referent, proof_req)?,
revocation_interval: _get_revocation_interval(referent, proof_req)?,
timestamp: None,
rev_reg_id: cred_info.rev_reg_id.clone(),
cred_rev_id: cred_info.cred_rev_id.clone(),
Expand Down Expand Up @@ -337,17 +337,14 @@ pub mod unit_tests {
use aries_vcx_core::ledger::indy::pool::test_utils::get_temp_dir_path;

use super::*;
use crate::{
core::profile::vdrtools_profile::VdrtoolsProfile,
utils::{
constants::{
ADDRESS_CRED_DEF_ID, ADDRESS_CRED_ID, ADDRESS_CRED_REV_ID, ADDRESS_REV_REG_ID,
ADDRESS_SCHEMA_ID, CRED_DEF_ID, CRED_REV_ID, LICENCE_CRED_ID, REV_REG_ID,
REV_STATE_JSON, SCHEMA_ID,
},
devsetup::*,
mockdata::profile::{mock_anoncreds::MockAnoncreds, mock_ledger::MockLedger},
use crate::utils::{
constants::{
ADDRESS_CRED_DEF_ID, ADDRESS_CRED_ID, ADDRESS_CRED_REV_ID, ADDRESS_REV_REG_ID,
ADDRESS_SCHEMA_ID, CRED_DEF_ID, CRED_REV_ID, LICENCE_CRED_ID, REV_REG_ID,
REV_STATE_JSON, SCHEMA_ID,
},
devsetup::*,
mockdata::profile::{mock_anoncreds::MockAnoncreds, mock_ledger::MockLedger},
};

fn proof_req_no_interval() -> ProofRequestData {
Expand Down Expand Up @@ -401,7 +398,7 @@ pub mod unit_tests {
let credential_def = build_cred_defs_json_prover(&ledger_read, &creds)
.await
.unwrap();
assert!(credential_def.len() > 0);
assert!(!credential_def.is_empty());
assert!(credential_def
.contains(r#""id":"V4SGRU86Z58d6TV7PBUe6f:3:CL:47:tag1","schemaId":"47""#));
}
Expand Down Expand Up @@ -448,7 +445,7 @@ pub mod unit_tests {
let schemas = build_schemas_json_prover(&ledger_read, &creds)
.await
.unwrap();
assert!(schemas.len() > 0);
assert!(!schemas.is_empty());
assert!(schemas.contains(
r#""id":"2hoqvcwupRTUNkXn6ArYzs:2:test-licence:4.4.4","name":"test-licence""#
));
Expand Down Expand Up @@ -691,7 +688,7 @@ pub mod unit_tests {
"zip_2": { "name": "zip_2" }
},
"requested_predicates": {},
"non_revoked": {"from": 098, "to": 123}
"non_revoked": {"from": 98, "to": 123}
});
let proof_req: ProofRequestData = serde_json::from_value(proof_req).unwrap();
let requested_credential = build_requested_credentials_json(
Expand Down Expand Up @@ -747,7 +744,7 @@ pub mod unit_tests {
"zip_2": { "name": "zip" }
},
"requested_predicates": {},
"non_revoked": {"from": 098, "to": 123}
"non_revoked": {"from": 98, "to": 123}
});
let proof_req: ProofRequestData = serde_json::from_value(proof_req).unwrap();

Expand All @@ -771,7 +768,7 @@ pub mod unit_tests {

// when attribute interval is None, defaults to proof req interval
let interval = Some(NonRevokedInterval {
from: Some(098),
from: Some(98),
to: Some(123),
});
assert_eq!(
Expand Down
Loading

0 comments on commit b25d388

Please sign in to comment.