Skip to content

Commit 79d6097

Browse files
authored
Merge pull request #228 from bobozaur/refactor/aries_improvements
refactor: services function signatures improvements
2 parents 1eb7aa2 + 764a3df commit 79d6097

File tree

16 files changed

+291
-278
lines changed

16 files changed

+291
-278
lines changed

src/data_types/cred_def.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ mod test_cred_def {
9797
issuer::create_schema(
9898
"name",
9999
"1.0",
100-
"did:example",
100+
"did:example".try_into().unwrap(),
101101
vec!["name".to_owned(), "age".to_owned()].into(),
102102
)
103103
.expect("Unable to create Schema")
@@ -110,9 +110,9 @@ mod test_cred_def {
110110
) {
111111
let schema = schema();
112112
issuer::create_credential_definition(
113-
"did:example/schema",
113+
"did:example/schema".try_into().unwrap(),
114114
&schema,
115-
"did:exampple",
115+
"did:exampple".try_into().unwrap(),
116116
"default-tag",
117117
SignatureType::CL,
118118
CredentialDefinitionConfig::default(),
@@ -124,9 +124,9 @@ mod test_cred_def {
124124
fn should_create_credential_definition() {
125125
let schema = schema();
126126
let result = issuer::create_credential_definition(
127-
"did:example/schema",
127+
"did:example/schema".try_into().unwrap(),
128128
&schema,
129-
"did:exampple",
129+
"did:exampple".try_into().unwrap(),
130130
"default-tag",
131131
SignatureType::CL,
132132
CredentialDefinitionConfig::default(),

src/data_types/cred_request.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,14 @@ mod cred_req_tests {
122122
const LINK_SECRET_ID: &str = "link:secret:id";
123123

124124
fn cred_def() -> Result<(CredentialDefinition, CredentialKeyCorrectnessProof)> {
125-
let credential_definition_issuer_id = "sample:id";
126-
125+
let issuer_id = "sample:uri".try_into()?;
126+
let schema_id = "schema:id".try_into()?;
127+
let credential_definition_issuer_id = "sample:id".try_into()?;
127128
let attr_names = AttributeNames::from(vec!["name".to_owned(), "age".to_owned()]);
128-
let schema = create_schema("schema:name", "1.0", "sample:uri", attr_names)?;
129+
130+
let schema = create_schema("schema:name", "1.0", issuer_id, attr_names)?;
129131
let cred_def = create_credential_definition(
130-
"schema:id",
132+
schema_id,
131133
&schema,
132134
credential_definition_issuer_id,
133135
"default",
@@ -150,12 +152,16 @@ mod cred_req_tests {
150152
) -> Result<CredentialOffer> {
151153
if is_legacy {
152154
create_credential_offer(
153-
LEGACY_SCHEMA_IDENTIFIER,
154-
LEGACY_CRED_DEF_IDENTIFIER,
155+
LEGACY_SCHEMA_IDENTIFIER.try_into()?,
156+
LEGACY_CRED_DEF_IDENTIFIER.try_into()?,
155157
&correctness_proof,
156158
)
157159
} else {
158-
create_credential_offer(NEW_IDENTIFIER, NEW_IDENTIFIER, &correctness_proof)
160+
create_credential_offer(
161+
NEW_IDENTIFIER.try_into()?,
162+
NEW_IDENTIFIER.try_into()?,
163+
&correctness_proof,
164+
)
159165
}
160166
}
161167

src/data_types/rev_status_list.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,9 @@ impl TryFrom<&RevocationStatusList> for Option<RevocationRegistry> {
4141
type Error = Error;
4242

4343
fn try_from(value: &RevocationStatusList) -> std::result::Result<Self, Self::Error> {
44-
let value = match value.registry {
45-
Some(registry) => Some(RevocationRegistry {
46-
value: registry.into(),
47-
}),
48-
None => None,
49-
};
44+
let value = value.registry.map(|registry| RevocationRegistry {
45+
value: registry.into(),
46+
});
5047

5148
Ok(value)
5249
}
@@ -258,7 +255,7 @@ mod rev_reg_tests {
258255

259256
list.update(None, Some(BTreeSet::from([0u32])), None, Some(1245))
260257
.unwrap();
261-
assert_eq!(list.get(0usize).unwrap(), false);
258+
assert!(!list.get(0usize).unwrap());
262259
assert_eq!(list.timestamp().unwrap(), 1245);
263260
}
264261
}

src/data_types/schema.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ pub struct Schema {
1717
pub issuer_id: IssuerId,
1818
}
1919

20+
// QUESTION: If these must be unique, why not directly store them as a set?
2021
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
2122
pub struct AttributeNames(pub Vec<String>);
2223

@@ -55,11 +56,7 @@ impl Validatable for Schema {
5556
impl Validatable for AttributeNames {
5657
fn validate(&self) -> Result<(), ValidationError> {
5758
let mut unique = HashSet::new();
58-
let is_unique = self
59-
.0
60-
.clone()
61-
.into_iter()
62-
.all(move |name| unique.insert(name));
59+
let is_unique = self.0.iter().all(move |name| unique.insert(name));
6360

6461
if !is_unique {
6562
return Err("Attributes inside the schema must be unique".into());

src/ffi/cred_def.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ pub extern "C" fn anoncreds_create_credential_definition(
3232
let tag = tag.as_opt_str().ok_or_else(|| err_msg!("Missing tag"))?;
3333
let schema_id = schema_id
3434
.as_opt_str()
35-
.ok_or_else(|| err_msg!("Missing schema id"))?;
35+
.ok_or_else(|| err_msg!("Missing schema id"))?
36+
.try_into()?;
3637
let signature_type = {
3738
let stype = signature_type
3839
.as_opt_str()
@@ -41,7 +42,9 @@ pub extern "C" fn anoncreds_create_credential_definition(
4142
};
4243
let issuer_id = issuer_id
4344
.as_opt_str()
44-
.ok_or_else(|| err_msg!("Missing issuer id"))?;
45+
.ok_or_else(|| err_msg!("Missing issuer id"))?
46+
.try_into()?;
47+
4548
let (cred_def, cred_def_pvt, key_proof) = create_credential_definition(
4649
schema_id,
4750
schema.load()?.cast_ref()?,

src/ffi/cred_offer.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ pub extern "C" fn anoncreds_create_credential_offer(
1515
check_useful_c_ptr!(cred_offer_p);
1616
let schema_id = schema_id
1717
.as_opt_str()
18-
.ok_or_else(|| err_msg!("Missing schema ID"))?;
18+
.ok_or_else(|| err_msg!("Missing schema ID"))?
19+
.try_into()?;
1920
let cred_def_id = cred_def_id
2021
.as_opt_str()
21-
.ok_or_else(|| err_msg!("Missing cred def ID"))?;
22+
.ok_or_else(|| err_msg!("Missing cred def ID"))?
23+
.try_into()?;
2224
let cred_offer =
2325
create_credential_offer(schema_id, cred_def_id, key_proof.load()?.cast_ref()?)?;
2426
let cred_offer = ObjectHandle::create(cred_offer)?;

src/ffi/revocation.rs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub extern "C" fn anoncreds_create_revocation_status_list(
2424
rev_reg_def_id: FfiStr,
2525
rev_reg_def: ObjectHandle,
2626
reg_rev_priv: ObjectHandle,
27-
issuer_id: FfiStr,
27+
_issuer_id: FfiStr, // leaving it here not to break existing code
2828
issuance_by_default: i8,
2929
timestamp: i64,
3030
rev_status_list_p: *mut ObjectHandle,
@@ -33,10 +33,9 @@ pub extern "C" fn anoncreds_create_revocation_status_list(
3333
check_useful_c_ptr!(rev_status_list_p);
3434
let rev_reg_def_id = rev_reg_def_id
3535
.as_opt_str()
36-
.ok_or_else(|| err_msg!("Missing rev_reg_def_id"))?;
37-
let issuer_id = issuer_id
38-
.as_opt_str()
39-
.ok_or_else(|| err_msg!("Missing issuer_id"))?;
36+
.ok_or_else(|| err_msg!("Missing rev_reg_def_id"))?
37+
.try_into()?;
38+
4039
let timestamp = if timestamp <= 0 {
4140
None
4241
} else {
@@ -48,7 +47,6 @@ pub extern "C" fn anoncreds_create_revocation_status_list(
4847
rev_reg_def_id,
4948
rev_reg_def.load()?.cast_ref()?,
5049
reg_rev_priv.load()?.cast_ref()?,
51-
issuer_id,
5250
issuance_by_default != 0,
5351
timestamp,
5452
)?;
@@ -134,7 +132,7 @@ pub extern "C" fn anoncreds_update_revocation_status_list_timestamp_only(
134132
pub extern "C" fn anoncreds_create_revocation_registry_def(
135133
cred_def: ObjectHandle,
136134
cred_def_id: FfiStr,
137-
issuer_id: FfiStr,
135+
_issuer_id: FfiStr, // leaving it here not to break existing code
138136
tag: FfiStr,
139137
rev_reg_type: FfiStr,
140138
max_cred_num: i64,
@@ -148,10 +146,8 @@ pub extern "C" fn anoncreds_create_revocation_registry_def(
148146
let tag = tag.as_opt_str().ok_or_else(|| err_msg!("Missing tag"))?;
149147
let cred_def_id = cred_def_id
150148
.as_opt_str()
151-
.ok_or_else(|| err_msg!("Missing cred def id"))?;
152-
let issuer_id = issuer_id
153-
.as_opt_str()
154-
.ok_or_else(|| err_msg!("Missing issuer id"))?;
149+
.ok_or_else(|| err_msg!("Missing cred def id"))?
150+
.try_into()?;
155151
let rev_reg_type = {
156152
let rtype = rev_reg_type
157153
.as_opt_str()
@@ -162,7 +158,6 @@ pub extern "C" fn anoncreds_create_revocation_registry_def(
162158
let (reg_def, reg_def_private) = create_revocation_registry_def(
163159
cred_def.load()?.cast_ref()?,
164160
cred_def_id,
165-
issuer_id,
166161
tag,
167162
rev_reg_type,
168163
max_cred_num

src/ffi/schema.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ pub extern "C" fn anoncreds_create_schema(
2424
.ok_or_else(|| err_msg!("Missing schema version"))?;
2525
let issuer_id = issuer_id
2626
.as_opt_str()
27-
.ok_or_else(|| err_msg!("Missing issuer_id"))?;
27+
.ok_or_else(|| err_msg!("Missing issuer_id"))?
28+
.try_into()?;
2829
let schema = create_schema(
2930
schema_name,
3031
schema_version,

0 commit comments

Comments
 (0)