Skip to content

Commit

Permalink
add check for when definition format is empty
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Tate <[email protected]>
  • Loading branch information
Ryanmtate committed Oct 11, 2024
1 parent 7b9be0c commit 463b8b2
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 10 deletions.
7 changes: 2 additions & 5 deletions src/credential/json_vc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use uuid::Uuid;

use crate::{CredentialType, KeyAlias};

use super::{Credential, VcdmVersion};
use super::{Credential, CredentialFormat, VcdmVersion};

#[derive(uniffi::Object, Debug, Clone)]
/// A verifiable credential secured as JSON.
Expand Down Expand Up @@ -125,10 +125,7 @@ impl JsonVc {
pub fn check_presentation_definition(&self, definition: &PresentationDefinition) -> bool {
// If the credential does not match the definition requested format,
// then return false.
if !definition
.format()
.contains_key(&ClaimFormatDesignation::LdpVc)
{
if !definition.format().is_empty() && !definition.contains_format(CredentialFormat::LdpVc) {
return false;
}

Expand Down
7 changes: 3 additions & 4 deletions src/credential/jwt_vc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use uuid::Uuid;

use crate::{CredentialType, KeyAlias};

use super::{Credential, VcdmVersion};
use super::{Credential, CredentialFormat, VcdmVersion};

#[derive(uniffi::Object, Debug, Clone)]
/// A verifiable credential secured as a JWT.
Expand Down Expand Up @@ -164,9 +164,8 @@ impl JwtVc {
pub fn check_presentation_definition(&self, definition: &PresentationDefinition) -> bool {
// If the credential does not match the definition requested format,
// then return false.
if !definition
.format()
.contains_key(&ClaimFormatDesignation::JwtVcJson)
if !definition.format().is_empty()
&& !definition.contains_format(CredentialFormat::JwtVcJson)
{
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/credential/sd_jwt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl SdJwt {
pub fn check_presentation_definition(&self, definition: &PresentationDefinition) -> bool {
// If the credential does not match the definition requested format,
// then return false.
if !definition.contains_format(CredentialFormat::SdJwt) {
if !definition.format().is_empty() && !definition.contains_format(CredentialFormat::SdJwt) {
println!(
"Credential does not match the requested format: {:?}.",
definition.format()
Expand Down

0 comments on commit 463b8b2

Please sign in to comment.