Skip to content
This repository has been archived by the owner on Feb 29, 2024. It is now read-only.

Commit

Permalink
FIXED IS-840: get-creds panics when req-attr, req-pred specs cite dif…
Browse files Browse the repository at this point in the history
…ferent cred def ids

Signed-off-by: artem.ivanov <[email protected]>
  • Loading branch information
Artemkaaas committed Jul 26, 2018
1 parent 0f274df commit 53770c3
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
11 changes: 9 additions & 2 deletions libindy/src/commands/anoncreds/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use self::indy_crypto::utils::json::{JsonDecodable, JsonEncodable};
use super::tails::SDKTailsAccessor;

use domain::anoncreds::schema::{Schema, schemas_map_to_schemas_v1_map};
use domain::anoncreds::credential::{Credential, CredentialInfo};
use domain::anoncreds::credential::{Credential, CredentialInfo, AttributeValues};
use domain::anoncreds::credential_definition::{CredentialDefinition, CredentialDefinitionV1, cred_defs_map_to_cred_defs_v1_map};
use domain::anoncreds::credential_offer::CredentialOffer;
use domain::anoncreds::credential_request::{CredentialRequest, CredentialRequestMetadata};
Expand Down Expand Up @@ -805,8 +805,15 @@ impl ProverCommandExecutor {
let (referent, credential) = self._get_credential(&credential_record)?;

if let Some(predicate) = predicate_info {

let cred_values_common_view: HashMap<String, AttributeValues> =
credential.values
.iter()
.map(|(key, value)| (attr_common_view(&key), value.clone()))
.collect();

let satisfy = self.anoncreds_service.prover.attribute_satisfy_predicate(predicate,
&credential.values[&attr_common_view(&predicate.name)].encoded)?;
&cred_values_common_view[&attr_common_view(&predicate.name)].encoded)?;
if !satisfy { continue; }
}

Expand Down
27 changes: 27 additions & 0 deletions libindy/tests/anoncreds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1985,6 +1985,33 @@ mod high_cases {

WalletUtils::close_wallet(wallet_handle).unwrap();
}

#[test]
fn prover_get_credentials_for_proof_req_works_for_predicate_uppercase() {
AnoncredsUtils::init_common_wallet();

let wallet_handle = WalletUtils::open_wallet(ANONCREDS_WALLET_CONFIG, WALLET_CREDENTIALS).unwrap();

let proof_req = json!({
"nonce":"123432421212",
"name":"proof_req_1",
"version":"0.1",
"requested_attributes": json!({}),
"requested_predicates": json!({
"predicate1_referent": json!({ "name":"AGe", "p_type":">=", "p_value":18 })
}),
}).to_string();

let credentials_json = AnoncredsUtils::prover_get_credentials_for_proof_req(wallet_handle, &proof_req).unwrap();

let credentials: CredentialsForProofRequest = serde_json::from_str(&credentials_json).unwrap();
assert_eq!(credentials.predicates.len(), 1);

let credentials_for_predicate_1 = credentials.predicates.get("predicate1_referent").unwrap();
assert_eq!(credentials_for_predicate_1.len(), 2);

WalletUtils::close_wallet(wallet_handle).unwrap();
}
}

mod predicate_restrictions_wql_format {
Expand Down
2 changes: 1 addition & 1 deletion libindy/tests/utils/anoncreds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ impl AnoncredsUtils {
"sex".to_string() => AttributeValues {raw: "male".to_string(), encoded: "2142657394558967239210949258394838228692050081607692519917028371144233115103".to_string()},
"name".to_string() => AttributeValues {raw: "Alexander".to_string(), encoded: "21332817548165488690172217217278169335".to_string()},
"height".to_string() => AttributeValues {raw: "170".to_string(), encoded: "170".to_string()},
"age".to_string() => AttributeValues {raw: "28".to_string(), encoded: "28".to_string()}
"Age".to_string() => AttributeValues {raw: "28".to_string(), encoded: "28".to_string()}
}
}

Expand Down

0 comments on commit 53770c3

Please sign in to comment.