Skip to content

Commit

Permalink
clean up clippy warnings
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Whitehead <[email protected]>
  • Loading branch information
andrewwhitehead committed Sep 20, 2023
1 parent be77295 commit ee4b2fb
Show file tree
Hide file tree
Showing 31 changed files with 287 additions and 327 deletions.
1 change: 1 addition & 0 deletions indy-credx/src/ffi/cred_def.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::os::raw::c_char;
use std::str::FromStr;

use ffi_support::{rust_string_to_c, FfiStr};
use indy_data_types::Qualifiable;
Expand Down
15 changes: 7 additions & 8 deletions indy-credx/src/ffi/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub(crate) static FFI_OBJECTS: Lazy<Mutex<BTreeMap<ObjectHandle, IndyObject>>> =

static FFI_OBJECT_COUNTER: AtomicUsize = AtomicUsize::new(0);

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[repr(transparent)]
pub struct ObjectHandle(pub usize);

Expand Down Expand Up @@ -71,12 +71,6 @@ impl ObjectHandle {
}
}

impl Default for ObjectHandle {
fn default() -> Self {
Self(0)
}
}

impl std::fmt::Display for ObjectHandle {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}({})", stringify!($newtype), self.0)
Expand Down Expand Up @@ -112,6 +106,7 @@ pub(crate) struct IndyObject(Arc<dyn AnyIndyObject>);

impl IndyObject {
pub fn new<O: AnyIndyObject + 'static>(value: O) -> Self {
assert!(std::mem::size_of::<O>() != 0);
Self(Arc::new(value))
}

Expand All @@ -135,6 +130,10 @@ impl IndyObject {

impl PartialEq for IndyObject {
fn eq(&self, other: &IndyObject) -> bool {
#[allow(clippy::vtable_address_comparisons)]
// this is allowed only because we create all such objects
// in one place (the `new` method) and ensure they are not
// zero-sized.
Arc::ptr_eq(&self.0, &other.0)
}
}
Expand Down Expand Up @@ -252,7 +251,7 @@ pub(crate) struct IndyObjectList(Vec<IndyObject>);
impl IndyObjectList {
pub fn load(handles: &[ObjectHandle]) -> Result<Self> {
let loaded = handles
.into_iter()
.iter()
.map(ObjectHandle::load)
.collect::<Result<_>>()?;
Ok(Self(loaded))
Expand Down
1 change: 1 addition & 0 deletions indy-credx/src/ffi/presentation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ pub extern "C" fn credx_verify_presentation_legacy(
)
}

#[allow(clippy::too_many_arguments)]
fn _credx_verify_presentation(
presentation: ObjectHandle,
pres_req: ObjectHandle,
Expand Down
1 change: 1 addition & 0 deletions indy-credx/src/ffi/revocation.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::collections::BTreeSet;
use std::convert::TryInto;
use std::os::raw::c_char;
use std::str::FromStr;

use ffi_support::{rust_string_to_c, FfiStr};
use indy_data_types::Qualifiable;
Expand Down
2 changes: 1 addition & 1 deletion indy-credx/src/services/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::anoncreds_clsignatures::{
use crate::error::Result;

pub fn attr_common_view(attr: &str) -> String {
attr.replace(" ", "").to_lowercase()
attr.replace(' ', "").to_lowercase()
}

pub fn build_credential_schema(attrs: &HashSet<String>) -> Result<CredentialSchema> {
Expand Down
38 changes: 14 additions & 24 deletions indy-credx/src/services/issuer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub fn create_schema(
origin_did, schema_name, schema_version, attr_names);

origin_did.validate()?;
let schema_id = SchemaId::new(&origin_did, schema_name, schema_version);
let schema_id = SchemaId::new(origin_did, schema_name, schema_version);
let schema = SchemaV1 {
id: schema_id,
name: schema_name.to_string(),
Expand Down Expand Up @@ -57,12 +57,12 @@ pub fn make_credential_definition_id(
};
let schema_infix_id = schema_seq_no
.map(|n| SchemaId(n.to_string()))
.unwrap_or(schema_id.clone());
.unwrap_or(schema_id);

Ok(CredentialDefinitionId::new(
origin_did,
&schema_infix_id,
&signature_type.to_str(),
signature_type.to_str(),
tag,
))
}
Expand All @@ -84,9 +84,7 @@ pub fn create_credential_definition(
config
);

let schema = match schema {
Schema::SchemaV1(s) => s,
};
let Schema::SchemaV1(schema) = schema;
let cred_def_id =
make_credential_definition_id(origin_did, &schema.id, schema.seq_no, tag, signature_type)?;

Expand Down Expand Up @@ -142,9 +140,7 @@ pub fn make_revocation_registry_id(
tag: &str,
rev_reg_type: RegistryType,
) -> Result<RevocationRegistryId> {
let cred_def = match cred_def {
CredentialDefinition::CredentialDefinitionV1(c) => c,
};
let CredentialDefinition::CredentialDefinitionV1(cred_def) = cred_def;

let origin_did = match (origin_did.get_method(), cred_def.id.get_method()) {
(None, Some(_)) => {
Expand All @@ -157,9 +153,9 @@ pub fn make_revocation_registry_id(
};

Ok(RevocationRegistryId::new(
&origin_did,
origin_did,
&cred_def.id,
&rev_reg_type.to_str(),
rev_reg_type.to_str(),
tag,
))
}
Expand All @@ -186,9 +182,7 @@ where

let rev_reg_id = make_revocation_registry_id(origin_did, cred_def, tag, rev_reg_type)?;

let cred_def = match cred_def {
CredentialDefinition::CredentialDefinitionV1(c) => c,
};
let CredentialDefinition::CredentialDefinitionV1(cred_def) = cred_def;
let credential_pub_key = cred_def.get_public_key().map_err(err_map!(
Unexpected,
"Error fetching public key from credential definition"
Expand All @@ -211,13 +205,13 @@ where
max_cred_num,
issuance_type,
public_keys: rev_keys_pub,
tails_location: tails_location.clone(),
tails_location,
tails_hash,
};

let revoc_reg_def = RevocationRegistryDefinition::RevocationRegistryDefinitionV1(
RevocationRegistryDefinitionV1 {
id: rev_reg_id.clone(),
id: rev_reg_id,
revoc_def_type: rev_reg_type,
tag: tag.to_string(),
cred_def_id: cred_def.id.clone(),
Expand Down Expand Up @@ -260,9 +254,7 @@ pub fn update_revocation_registry(
))?
}
};
let rev_reg_def = match rev_reg_def {
RevocationRegistryDefinition::RevocationRegistryDefinitionV1(v1) => v1,
};
let RevocationRegistryDefinition::RevocationRegistryDefinitionV1(rev_reg_def) = rev_reg_def;
let mut rev_reg = match rev_reg {
RevocationRegistry::RevocationRegistryV1(v1) => v1.value.clone(),
};
Expand Down Expand Up @@ -292,9 +284,7 @@ pub fn create_credential_offer(

let nonce = Nonce::new().map_err(err_map!(Unexpected, "Error creating nonce"))?;

let cred_def = match cred_def {
CredentialDefinition::CredentialDefinitionV1(c) => c,
};
let CredentialDefinition::CredentialDefinitionV1(cred_def) = cred_def;

let key_correctness_proof = correctness_proof
.try_clone()
Expand Down Expand Up @@ -370,8 +360,8 @@ pub fn create_credential(
)?;

let cred_rev_reg_id = match cred_offer.method_name.as_ref() {
Some(ref _method_name) => Some(reg_reg_id.to_unqualified()),
_ => Some(reg_reg_id.clone()),
Some(_method_name) => Some(reg_reg_id.to_unqualified()),
_ => Some(reg_reg_id),
};
(
credential_signature,
Expand Down
38 changes: 13 additions & 25 deletions indy-credx/src/services/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ pub fn create_credential_request(
credential_offer
);

let cred_def = match cred_def {
CredentialDefinition::CredentialDefinitionV1(cd) => cd,
};
let CredentialDefinition::CredentialDefinitionV1(cred_def) = cred_def;
let credential_pub_key = CredentialPublicKey::build_from_parts(
&cred_def.value.primary,
cred_def.value.revocation.as_ref(),
Expand Down Expand Up @@ -93,9 +91,7 @@ pub fn process_credential(
trace!("process_credential >>> credential: {:?}, cred_request_metadata: {:?}, link_secret: {:?}, cred_def: {:?}, rev_reg_def: {:?}",
credential, cred_request_metadata, secret!(&link_secret), cred_def, rev_reg_def);

let cred_def = match cred_def {
CredentialDefinition::CredentialDefinitionV1(cd) => cd,
};
let CredentialDefinition::CredentialDefinitionV1(cred_def) = cred_def;
let credential_pub_key = CredentialPublicKey::build_from_parts(
&cred_def.value.primary,
cred_def.value.revocation.as_ref(),
Expand Down Expand Up @@ -154,9 +150,10 @@ pub fn create_presentation(
let mut proof_builder = ClProver::new_proof_builder()?;
proof_builder.add_common_attribute("master_secret")?;

let mut requested_proof = RequestedProof::default();

requested_proof.self_attested_attrs = self_attested.unwrap_or_default();
let mut requested_proof = RequestedProof {
self_attested_attrs: self_attested.unwrap_or_default(),
..Default::default()
};

let mut sub_proof_index = 0;
let non_credential_schema = build_non_credential_schema()?;
Expand All @@ -168,22 +165,17 @@ pub fn create_presentation(
}
let credential = present.cred;

let schema = *schemas
let Schema::SchemaV1(schema) = *schemas
.get(&credential.schema_id)
.ok_or_else(|| err_msg!("Schema not provided for ID: {}", credential.schema_id))?;
let schema = match schema {
Schema::SchemaV1(schema) => schema,
};

let cred_def = *cred_defs.get(&credential.cred_def_id).ok_or_else(|| {
err_msg!(
"Credential Definition not provided for ID: {}",
credential.cred_def_id
)
})?;
let cred_def = match cred_def {
CredentialDefinition::CredentialDefinitionV1(cd) => cd,
};
let CredentialDefinition::CredentialDefinitionV1(cred_def) = cred_def;

let credential_pub_key = CredentialPublicKey::build_from_parts(
&cred_def.value.primary,
Expand Down Expand Up @@ -272,12 +264,8 @@ rev_reg_delta: {:?}, rev_reg_idx: {}, timestamp: {:?}, rev_state: {:?}",
rev_state
);

let revoc_reg_def = match revoc_reg_def {
RevocationRegistryDefinition::RevocationRegistryDefinitionV1(v1) => v1,
};
let rev_reg_delta = match rev_reg_delta {
RevocationRegistryDelta::RevocationRegistryDeltaV1(v1) => v1,
};
let RevocationRegistryDefinition::RevocationRegistryDefinitionV1(revoc_reg_def) = revoc_reg_def;
let RevocationRegistryDelta::RevocationRegistryDeltaV1(rev_reg_delta) = rev_reg_delta;

let witness = match rev_state {
None => Witness::new(
Expand Down Expand Up @@ -377,7 +365,7 @@ fn get_credential_values_for_attribute(

let res = credential_attrs
.iter()
.find(|&(ref key, _)| attr_common_view(key) == attr_common_view(&requested_attr))
.find(|(key, _)| attr_common_view(key) == attr_common_view(requested_attr))
.map(|(_, values)| values.clone());

trace!(
Expand Down Expand Up @@ -406,7 +394,7 @@ fn update_requested_proof(

if let Some(name) = &attribute.name {
let attribute_values =
get_credential_values_for_attribute(&credential.values.0, &name).ok_or_else(
get_credential_values_for_attribute(&credential.values.0, name).ok_or_else(
|| err_msg!("Credential value not found for attribute {:?}", name),
)?;

Expand All @@ -422,7 +410,7 @@ fn update_requested_proof(
let mut value_map: HashMap<String, AttributeValue> = HashMap::new();
for name in names {
let attr_value =
get_credential_values_for_attribute(&credential.values.0, &name)
get_credential_values_for_attribute(&credential.values.0, name)
.ok_or_else(|| {
err_msg!("Credential value not found for attribute {:?}", name)
})?;
Expand Down
16 changes: 4 additions & 12 deletions indy-credx/src/services/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use crate::anoncreds_clsignatures::{RevocationRegistry as CryptoRevocationRegist
use crate::error::Error;
use crate::services::helpers::encode_credential_attribute;

#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
pub struct CredentialDefinitionConfig {
pub support_revocation: bool,
}
Expand All @@ -38,14 +38,6 @@ impl CredentialDefinitionConfig {
}
}

impl Default for CredentialDefinitionConfig {
fn default() -> Self {
Self {
support_revocation: false,
}
}
}

impl Validatable for CredentialDefinitionConfig {}

#[derive(Debug, Default)]
Expand Down Expand Up @@ -81,9 +73,9 @@ impl MakeCredentialValues {
}
}

impl Into<CredentialValues> for MakeCredentialValues {
fn into(self) -> CredentialValues {
self.0
impl From<MakeCredentialValues> for CredentialValues {
fn from(val: MakeCredentialValues) -> CredentialValues {
val.0
}
}

Expand Down
Loading

0 comments on commit ee4b2fb

Please sign in to comment.