Skip to content

Commit

Permalink
fix clippy warnings
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Tate <[email protected]>
  • Loading branch information
Ryanmtate committed Aug 23, 2024
1 parent 7733f65 commit 54c0f79
Show file tree
Hide file tree
Showing 10 changed files with 310 additions and 1,444 deletions.
50 changes: 19 additions & 31 deletions src/core/credential_format/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,23 +143,17 @@ impl ClaimFormatPayload {
///
/// This method is a no-op if self is not of type `AlgValuesSupported` or `Alg`.
pub fn add_alg(&mut self, alg: String) {
match self {
Self::Alg(algs) | Self::AlgValuesSupported(algs) => {
algs.push(alg);
}
_ => {} // Noop
if let Self::Alg(algs) | Self::AlgValuesSupported(algs) = self {
algs.push(alg);
}
}

/// Adds a proof type to the list of supported proof types.
///
/// This method is a no-op if self is not of type `ProofType`.
pub fn add_proof_type(&mut self, proof_type: String) {
match self {
Self::ProofType(proof_types) => {
proof_types.push(proof_type);
}
_ => {} // Noop
if let Self::ProofType(proof_types) = self {
proof_types.push(proof_type);
}
}
}
Expand Down Expand Up @@ -252,27 +246,21 @@ impl From<&str> for ClaimFormatDesignation {
}
}

impl Into<String> for ClaimFormatDesignation {
fn into(self) -> String {
match self {
Self::AcVc => "ac_vc".to_string(),
Self::AcVp => "ac_vp".to_string(),
Self::Jwt => "jwt".to_string(),
Self::JwtVc => "jwt_vc".to_string(),
Self::JwtVp => "jwt_vp".to_string(),
Self::JwtVcJson => "jwt_vc_json".to_string(),
Self::JwtVpJson => "jwt_vp_json".to_string(),
Self::Ldp => "ldp".to_string(),
Self::LdpVc => "ldp_vc".to_string(),
Self::LdpVp => "ldp_vp".to_string(),
Self::MsoMDoc => "mso_mdoc".to_string(),
Self::Other(s) => s,
impl From<ClaimFormatDesignation> for String {
fn from(format: ClaimFormatDesignation) -> Self {
match format {
ClaimFormatDesignation::AcVc => "ac_vc".to_string(),
ClaimFormatDesignation::AcVp => "ac_vp".to_string(),
ClaimFormatDesignation::Jwt => "jwt".to_string(),
ClaimFormatDesignation::JwtVc => "jwt_vc".to_string(),
ClaimFormatDesignation::JwtVp => "jwt_vp".to_string(),
ClaimFormatDesignation::JwtVcJson => "jwt_vc_json".to_string(),
ClaimFormatDesignation::JwtVpJson => "jwt_vp_json".to_string(),
ClaimFormatDesignation::Ldp => "ldp".to_string(),
ClaimFormatDesignation::LdpVc => "ldp_vc".to_string(),
ClaimFormatDesignation::LdpVp => "ldp_vp".to_string(),
ClaimFormatDesignation::MsoMDoc => "mso_mdoc".to_string(),
ClaimFormatDesignation::Other(s) => s,
}
}
}

impl std::fmt::Display for ClaimFormatDesignation {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "{}", self)
}
}
26 changes: 17 additions & 9 deletions src/core/input_descriptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,24 +175,22 @@ impl InputDescriptor {

let validator = constraint_field.validator();

let mut found_elements = false;

for field_path in constraint_field.path.iter() {
let field_elements = map_selector(field_path)
.context("Failed to select field elements from verifiable presentation.")?;

// Check if the field matches are empty.
if field_elements.is_empty() {
if let Some(ConstraintsLimitDisclosure::Required) =
self.constraints.limit_disclosure
{
bail!("Field elements are empty while limit disclosure is required.")
}

// According the specification, found here:
// [https://identity.foundation/presentation-exchange/spec/v2.0.0/#input-evaluation](https://identity.foundation/presentation-exchange/spec/v2.0.0/#input-evaluation)
// > If the result returned no JSONPath match, skip to the next path array element.
continue;
}

found_elements = true;

// If a filter is available with a valid schema, handle the field validation.
if let Some(Ok(schema_validator)) = validator.as_ref() {
let validated_fields = field_elements.iter().find(|element| {
Expand Down Expand Up @@ -220,6 +218,15 @@ impl InputDescriptor {
}
}
}

// If no elements are found, and limit disclosure is required, return an error.
if !found_elements {
if let Some(ConstraintsLimitDisclosure::Required) =
self.constraints.limit_disclosure
{
bail!("Field elements are empty while limit disclosure is required.")
}
}
}
}

Expand Down Expand Up @@ -295,10 +302,11 @@ impl Constraints {
pub fn is_required(&self) -> bool {
if let Some(fields) = self.fields() {
fields.iter().any(|field| field.is_required())
} else if let Some(ConstraintsLimitDisclosure::Required) = self.limit_disclosure() {
true
} else {
false
matches!(
self.limit_disclosure(),
Some(ConstraintsLimitDisclosure::Required)
)
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/core/metadata/parameters/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,10 @@ impl From<AuthorizationEncryptedResponseEnc> for Json {
mod test {
use serde_json::json;

use crate::core::object::UntypedObject;
use crate::presentation_exchange::{ClaimFormatDesignation, ClaimFormatPayload};
use crate::core::{
credential_format::{ClaimFormatDesignation, ClaimFormatPayload},
object::UntypedObject,
};

use super::*;

Expand Down
6 changes: 3 additions & 3 deletions src/core/metadata/parameters/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,9 @@ impl From<AuthorizationEncryptionEncValuesSupported> for Json {
mod test {
use serde_json::json;

use crate::{
core::object::UntypedObject,
presentation_exchange::{ClaimFormatDesignation, ClaimFormatPayload},
use crate::core::{
credential_format::{ClaimFormatDesignation, ClaimFormatPayload},
object::UntypedObject,
};

use super::*;
Expand Down
2 changes: 1 addition & 1 deletion src/core/presentation_submission.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ impl DescriptorMap {
/// - The id of the nested path must be the same as the parent id.
pub fn set_path_nested(mut self, mut path_nested: DescriptorMap) -> Self {
// Ensure the nested path has the same id as the parent.
path_nested.id = self.id.clone();
path_nested.id.clone_from(self.id());

self.path_nested = Some(Box::new(path_nested));

Expand Down
Loading

0 comments on commit 54c0f79

Please sign in to comment.