Skip to content

Commit 5123366

Browse files
Merge pull request #40 from andrewwhitehead/upd/dalek2
Update dalek dependencies & refactor
2 parents 942e693 + 684cafa commit 5123366

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+428
-742
lines changed

.github/workflows/build.yml

-3
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,6 @@ jobs:
9191
- name: Debug build
9292
run: cargo build --all-targets --features vendored
9393

94-
- name: Test indy-utils
95-
run: cargo test --manifest-path indy-utils/Cargo.toml
96-
9794
# - name: Test indy-data-types (CL)
9895
# run: cargo test --manifest-path indy-data-types/Cargo.toml --features cl
9996

Cargo.toml

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
[workspace]
2+
resolver = "2"
23

3-
members = [
4-
"indy-credx",
5-
"indy-data-types",
6-
"indy-test-utils",
7-
"indy-utils"
8-
]
4+
members = ["indy-credx", "indy-data-types"]
95

106
[profile.release]
117
panic = "abort"

README.md

-4
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ Shared Rust libraries for Hyperledger Indy.
66

77
- `indy-data-types`: Data type definitions for Schemas, Credential Definitions and other types related to credential issuance and processing.
88

9-
- `indy-test-utils`: Utilities for use in integration tests.
10-
11-
- `indy-utils`: Standard wrappers around binary data encodings. Includes support for normalizing transactions for signing, deriving DIDs and verification keys.
12-
139
## Credit
1410

1511
The initial implementation of `indy-shared-rs` was developed by the Verifiable Organizations Network (VON) team based at the Province of British Columbia, and derives largely from the implementations within [Hyperledger Indy-SDK](https://github.com/hyperledger/indy-sdk). To learn more about VON and what's happening with decentralized identity in British Columbia, please go to [https://vonx.io](https://vonx.io).

indy-credx/Cargo.toml

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "indy-credx"
3-
version = "1.0.3"
3+
version = "1.1.0"
44
authors = ["Hyperledger Indy Contributors <[email protected]>"]
55
description = "Verifiable credential issuance and presentation for Hyperledger Indy (https://www.hyperledger.org/projects), which provides a distributed-ledger-based foundation for self-sovereign identity (https://sovrin.org)."
66
edition = "2021"
@@ -25,16 +25,14 @@ vendored = ["indy-data-types/vendored"]
2525
[dependencies]
2626
env_logger = { version = "0.10", optional = true }
2727
ffi-support = { version = "0.4.0", optional = true }
28-
indy-data-types = { version = "0.6.1", features = [
28+
indy-data-types = { version = "0.7", features = [
2929
"cl_native",
3030
], path = "../indy-data-types" }
31-
indy-utils = { version = "0.6.0", default-features = false, path = "../indy-utils" }
3231
log = "0.4"
3332
once_cell = "1"
3433
rand = "0.8"
3534
regex = "1"
3635
serde = { version = "1.0", features = ["derive"] }
3736
serde_json = "1.0"
3837
sha2 = "0.10"
39-
thiserror = "1.0"
4038
zeroize = { version = "1", optional = true }

indy-credx/src/error.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ impl From<ErrorKind> for Error {
116116
}
117117
}
118118

119-
impl From<indy_utils::ValidationError> for Error {
120-
fn from(err: indy_utils::ValidationError) -> Self {
119+
impl From<indy_data_types::ValidationError> for Error {
120+
fn from(err: indy_data_types::ValidationError) -> Self {
121121
Error::from_opt_msg(ErrorKind::Input, err.context)
122122
}
123123
}

indy-credx/src/ffi/cred_def.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use std::os::raw::c_char;
2+
use std::str::FromStr;
23

34
use ffi_support::{rust_string_to_c, FfiStr};
4-
use indy_utils::Qualifiable;
5+
use indy_data_types::Qualifiable;
56

67
use super::error::{catch_error, ErrorCode};
78
use super::object::{IndyObjectId, ObjectHandle};

indy-credx/src/ffi/cred_offer.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use ffi_support::FfiStr;
2-
use indy_utils::Qualifiable;
2+
use indy_data_types::Qualifiable;
33

44
use super::error::{catch_error, ErrorCode};
55
use super::object::ObjectHandle;

indy-credx/src/ffi/cred_req.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use ffi_support::FfiStr;
2-
use indy_utils::Qualifiable;
2+
use indy_data_types::Qualifiable;
33

44
use super::error::{catch_error, ErrorCode};
55
use super::object::ObjectHandle;

indy-credx/src/ffi/object.rs

+43-6
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ use std::fmt::Debug;
44
use std::hash::{Hash, Hasher};
55
use std::ops::{Deref, DerefMut};
66
use std::os::raw::c_char;
7-
use std::sync::{Arc, Mutex};
7+
use std::sync::{atomic::AtomicUsize, Arc, Mutex};
88

99
use ffi_support::{rust_string_to_c, ByteBuffer};
10+
use indy_data_types::{Validatable, ValidationError};
1011
use once_cell::sync::Lazy;
1112
use serde::Serialize;
1213

@@ -16,9 +17,17 @@ use crate::error::Result;
1617
pub(crate) static FFI_OBJECTS: Lazy<Mutex<BTreeMap<ObjectHandle, IndyObject>>> =
1718
Lazy::new(|| Mutex::new(BTreeMap::new()));
1819

19-
indy_utils::new_handle_type!(ObjectHandle, FFI_OBJECT_COUNTER);
20+
static FFI_OBJECT_COUNTER: AtomicUsize = AtomicUsize::new(0);
21+
22+
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash, PartialOrd, Ord)]
23+
#[repr(transparent)]
24+
pub struct ObjectHandle(pub usize);
2025

2126
impl ObjectHandle {
27+
pub fn next() -> Self {
28+
Self(FFI_OBJECT_COUNTER.fetch_add(1, std::sync::atomic::Ordering::SeqCst) + 1)
29+
}
30+
2231
pub(crate) fn create<O: AnyIndyObject + 'static>(value: O) -> Result<Self> {
2332
let handle = Self::next();
2433
FFI_OBJECTS
@@ -62,9 +71,32 @@ impl ObjectHandle {
6271
}
6372
}
6473

65-
impl Default for ObjectHandle {
66-
fn default() -> Self {
67-
Self(0)
74+
impl std::fmt::Display for ObjectHandle {
75+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
76+
write!(f, "{}({})", stringify!($newtype), self.0)
77+
}
78+
}
79+
80+
impl std::ops::Deref for ObjectHandle {
81+
type Target = usize;
82+
fn deref(&self) -> &usize {
83+
&self.0
84+
}
85+
}
86+
87+
impl PartialEq<usize> for ObjectHandle {
88+
fn eq(&self, other: &usize) -> bool {
89+
self.0 == *other
90+
}
91+
}
92+
93+
impl Validatable for ObjectHandle {
94+
fn validate(&self) -> std::result::Result<(), ValidationError> {
95+
if **self == 0 {
96+
Err("Invalid handle: zero".into())
97+
} else {
98+
Ok(())
99+
}
68100
}
69101
}
70102

@@ -74,6 +106,7 @@ pub(crate) struct IndyObject(Arc<dyn AnyIndyObject>);
74106

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

@@ -97,6 +130,10 @@ impl IndyObject {
97130

98131
impl PartialEq for IndyObject {
99132
fn eq(&self, other: &IndyObject) -> bool {
133+
#[allow(clippy::vtable_address_comparisons)]
134+
// this is allowed only because we create all such objects
135+
// in one place (the `new` method) and ensure they are not
136+
// zero-sized.
100137
Arc::ptr_eq(&self.0, &other.0)
101138
}
102139
}
@@ -214,7 +251,7 @@ pub(crate) struct IndyObjectList(Vec<IndyObject>);
214251
impl IndyObjectList {
215252
pub fn load(handles: &[ObjectHandle]) -> Result<Self> {
216253
let loaded = handles
217-
.into_iter()
254+
.iter()
218255
.map(ObjectHandle::load)
219256
.collect::<Result<_>>()?;
220257
Ok(Self(loaded))

indy-credx/src/ffi/presentation.rs

+1
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ pub extern "C" fn credx_verify_presentation_legacy(
218218
)
219219
}
220220

221+
#[allow(clippy::too_many_arguments)]
221222
fn _credx_verify_presentation(
222223
presentation: ObjectHandle,
223224
pres_req: ObjectHandle,

indy-credx/src/ffi/revocation.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
use std::collections::BTreeSet;
22
use std::convert::TryInto;
33
use std::os::raw::c_char;
4+
use std::str::FromStr;
45

56
use ffi_support::{rust_string_to_c, FfiStr};
6-
use indy_utils::Qualifiable;
7+
use indy_data_types::Qualifiable;
78

89
use super::error::{catch_error, ErrorCode};
910
use super::object::{IndyObject, IndyObjectId, ObjectHandle};

indy-credx/src/ffi/schema.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::os::raw::c_char;
22

33
use ffi_support::{rust_string_to_c, FfiStr};
4-
use indy_utils::Qualifiable;
4+
use indy_data_types::Qualifiable;
55

66
use super::error::{catch_error, ErrorCode};
77
use super::object::{IndyObjectId, ObjectHandle};

indy-credx/src/services/helpers.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::anoncreds_clsignatures::{
1414
use crate::error::Result;
1515

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

2020
pub fn build_credential_schema(attrs: &HashSet<String>) -> Result<CredentialSchema> {

indy-credx/src/services/issuer.rs

+15-25
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use indy_data_types::anoncreds::{
1414
},
1515
schema::SchemaV1,
1616
};
17-
use indy_utils::{Qualifiable, Validatable};
17+
use indy_data_types::{Qualifiable, Validatable};
1818

1919
use super::tails::TailsWriter;
2020

@@ -29,7 +29,7 @@ pub fn create_schema(
2929
origin_did, schema_name, schema_version, attr_names);
3030

3131
origin_did.validate()?;
32-
let schema_id = SchemaId::new(&origin_did, schema_name, schema_version);
32+
let schema_id = SchemaId::new(origin_did, schema_name, schema_version);
3333
let schema = SchemaV1 {
3434
id: schema_id,
3535
name: schema_name.to_string(),
@@ -57,12 +57,12 @@ pub fn make_credential_definition_id(
5757
};
5858
let schema_infix_id = schema_seq_no
5959
.map(|n| SchemaId(n.to_string()))
60-
.unwrap_or(schema_id.clone());
60+
.unwrap_or(schema_id);
6161

6262
Ok(CredentialDefinitionId::new(
6363
origin_did,
6464
&schema_infix_id,
65-
&signature_type.to_str(),
65+
signature_type.to_str(),
6666
tag,
6767
))
6868
}
@@ -84,9 +84,7 @@ pub fn create_credential_definition(
8484
config
8585
);
8686

87-
let schema = match schema {
88-
Schema::SchemaV1(s) => s,
89-
};
87+
let Schema::SchemaV1(schema) = schema;
9088
let cred_def_id =
9189
make_credential_definition_id(origin_did, &schema.id, schema.seq_no, tag, signature_type)?;
9290

@@ -142,9 +140,7 @@ pub fn make_revocation_registry_id(
142140
tag: &str,
143141
rev_reg_type: RegistryType,
144142
) -> Result<RevocationRegistryId> {
145-
let cred_def = match cred_def {
146-
CredentialDefinition::CredentialDefinitionV1(c) => c,
147-
};
143+
let CredentialDefinition::CredentialDefinitionV1(cred_def) = cred_def;
148144

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

159155
Ok(RevocationRegistryId::new(
160-
&origin_did,
156+
origin_did,
161157
&cred_def.id,
162-
&rev_reg_type.to_str(),
158+
rev_reg_type.to_str(),
163159
tag,
164160
))
165161
}
@@ -186,9 +182,7 @@ where
186182

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

189-
let cred_def = match cred_def {
190-
CredentialDefinition::CredentialDefinitionV1(c) => c,
191-
};
185+
let CredentialDefinition::CredentialDefinitionV1(cred_def) = cred_def;
192186
let credential_pub_key = cred_def.get_public_key().map_err(err_map!(
193187
Unexpected,
194188
"Error fetching public key from credential definition"
@@ -211,13 +205,13 @@ where
211205
max_cred_num,
212206
issuance_type,
213207
public_keys: rev_keys_pub,
214-
tails_location: tails_location.clone(),
208+
tails_location,
215209
tails_hash,
216210
};
217211

218212
let revoc_reg_def = RevocationRegistryDefinition::RevocationRegistryDefinitionV1(
219213
RevocationRegistryDefinitionV1 {
220-
id: rev_reg_id.clone(),
214+
id: rev_reg_id,
221215
revoc_def_type: rev_reg_type,
222216
tag: tag.to_string(),
223217
cred_def_id: cred_def.id.clone(),
@@ -260,9 +254,7 @@ pub fn update_revocation_registry(
260254
))?
261255
}
262256
};
263-
let rev_reg_def = match rev_reg_def {
264-
RevocationRegistryDefinition::RevocationRegistryDefinitionV1(v1) => v1,
265-
};
257+
let RevocationRegistryDefinition::RevocationRegistryDefinitionV1(rev_reg_def) = rev_reg_def;
266258
let mut rev_reg = match rev_reg {
267259
RevocationRegistry::RevocationRegistryV1(v1) => v1.value.clone(),
268260
};
@@ -292,9 +284,7 @@ pub fn create_credential_offer(
292284

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

295-
let cred_def = match cred_def {
296-
CredentialDefinition::CredentialDefinitionV1(c) => c,
297-
};
287+
let CredentialDefinition::CredentialDefinitionV1(cred_def) = cred_def;
298288

299289
let key_correctness_proof = correctness_proof
300290
.try_clone()
@@ -370,8 +360,8 @@ pub fn create_credential(
370360
)?;
371361

372362
let cred_rev_reg_id = match cred_offer.method_name.as_ref() {
373-
Some(ref _method_name) => Some(reg_reg_id.to_unqualified()),
374-
_ => Some(reg_reg_id.clone()),
363+
Some(_method_name) => Some(reg_reg_id.to_unqualified()),
364+
_ => Some(reg_reg_id),
375365
};
376366
(
377367
credential_signature,

0 commit comments

Comments
 (0)