From 9b9aa2cc9c3eb362317043a87a346b8944cc5562 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Thu, 30 May 2019 11:40:37 +0300 Subject: [PATCH] Forwarded data types in Rust wrapper Signed-off-by: artem.ivanov --- wrappers/rust/src/anoncreds.rs | 69 +++++++++++++++---------------- wrappers/rust/src/blob_storage.rs | 2 +- wrappers/rust/src/cache.rs | 2 +- wrappers/rust/src/crypto.rs | 2 +- wrappers/rust/src/did.rs | 2 +- wrappers/rust/src/ledger.rs | 2 +- wrappers/rust/src/lib.rs | 16 +++++++ wrappers/rust/src/pairwise.rs | 2 +- wrappers/rust/src/payments.rs | 2 +- wrappers/rust/src/pool.rs | 2 +- wrappers/rust/src/wallet.rs | 2 +- 11 files changed, 58 insertions(+), 45 deletions(-) diff --git a/wrappers/rust/src/anoncreds.rs b/wrappers/rust/src/anoncreds.rs index 8772a43dba..8d0c9c2eda 100644 --- a/wrappers/rust/src/anoncreds.rs +++ b/wrappers/rust/src/anoncreds.rs @@ -15,7 +15,7 @@ use ffi::{ResponseStringStringCB, ResponseI32CB, ResponseEmptyCB, ResponseBoolCB}; -use ffi::{CommandHandle, WalletHandle, SearchHandle, BlobStorageReaderHandle, TailsWriterHandle}; +use {CommandHandle, WalletHandle, SearchHandle, BlobStorageReaderHandle, TailsWriterHandle}; use ffi::BlobStorageReaderCfgHandle; /// Create credential schema entity that describes credential attributes list and allows credentials @@ -53,7 +53,7 @@ fn _issuer_create_schema(command_handle: CommandHandle, issuer_did: &str, name: let attrs = c_str!(attrs); ErrorCode::from(unsafe { - anoncreds::indy_issuer_create_schema(command_handle, issuer_did.as_ptr(), name.as_ptr(), version.as_ptr(), attrs.as_ptr(), cb) + anoncreds::indy_issuer_create_schema(command_handle, issuer_did.as_ptr(), name.as_ptr(), version.as_ptr(), attrs.as_ptr(), cb) }) } @@ -96,16 +96,16 @@ fn _issuer_create_and_store_credential_def(command_handle: CommandHandle, wallet let config_json = c_str!(config_json); ErrorCode::from(unsafe { - anoncreds::indy_issuer_create_and_store_credential_def( - command_handle, - wallet_handle, - issuer_did.as_ptr(), - schema_json.as_ptr(), - tag.as_ptr(), - opt_c_ptr!(signature_type, signature_type_str), - config_json.as_ptr(), - cb - ) + anoncreds::indy_issuer_create_and_store_credential_def( + command_handle, + wallet_handle, + issuer_did.as_ptr(), + schema_json.as_ptr(), + tag.as_ptr(), + opt_c_ptr!(signature_type, signature_type_str), + config_json.as_ptr(), + cb + ) }) } @@ -169,7 +169,7 @@ fn _issuer_create_and_store_revoc_reg(command_handle: CommandHandle, wallet_hand let config_json = c_str!(config_json); ErrorCode::from(unsafe { - anoncreds::indy_issuer_create_and_store_revoc_reg(command_handle, wallet_handle, issuer_did.as_ptr(), opt_c_ptr!(revoc_def_type, revoc_def_type_str), tag.as_ptr(), cred_def_id.as_ptr(), config_json.as_ptr(), tails_writer_handle, cb) + anoncreds::indy_issuer_create_and_store_revoc_reg(command_handle, wallet_handle, issuer_did.as_ptr(), opt_c_ptr!(revoc_def_type, revoc_def_type_str), tag.as_ptr(), cred_def_id.as_ptr(), config_json.as_ptr(), tails_writer_handle, cb) }) } @@ -201,7 +201,7 @@ fn _issuer_create_credential_offer(command_handle: CommandHandle, wallet_handle: let cred_def_id = c_str!(cred_def_id); ErrorCode::from(unsafe { - anoncreds::indy_issuer_create_credential_offer(command_handle, wallet_handle, cred_def_id.as_ptr(), cb) + anoncreds::indy_issuer_create_credential_offer(command_handle, wallet_handle, cred_def_id.as_ptr(), cb) }) } @@ -271,7 +271,7 @@ fn _issuer_create_credential( let rev_reg_id_str = opt_c_str!(rev_reg_id); ErrorCode::from(unsafe { - anoncreds::indy_issuer_create_credential(command_handle, wallet_handle, cred_offer_json.as_ptr(), cred_req_json.as_ptr(), cred_values_json.as_ptr(), opt_c_ptr!(rev_reg_id, rev_reg_id_str), blob_storage_reader_handle, cb) + anoncreds::indy_issuer_create_credential(command_handle, wallet_handle, cred_offer_json.as_ptr(), cred_req_json.as_ptr(), cred_values_json.as_ptr(), opt_c_ptr!(rev_reg_id, rev_reg_id_str), blob_storage_reader_handle, cb) }) } @@ -309,7 +309,7 @@ fn _issuer_revoke_credential(command_handle: CommandHandle, let cred_revoc_id = c_str!(cred_revoc_id); ErrorCode::from(unsafe { - anoncreds::indy_issuer_revoke_credential(command_handle, wallet_handle, blob_storage_reader_cfg_handle, rev_reg_id.as_ptr(), cred_revoc_id.as_ptr(), cb) + anoncreds::indy_issuer_revoke_credential(command_handle, wallet_handle, blob_storage_reader_cfg_handle, rev_reg_id.as_ptr(), cred_revoc_id.as_ptr(), cb) }) } @@ -335,7 +335,7 @@ fn _issuer_merge_revocation_registry_deltas(command_handle: CommandHandle, rev_r let other_rev_reg_delta_json = c_str!(other_rev_reg_delta_json); ErrorCode::from(unsafe { - anoncreds::indy_issuer_merge_revocation_registry_deltas(command_handle, rev_reg_delta_json.as_ptr(), other_rev_reg_delta_json.as_ptr(), cb) + anoncreds::indy_issuer_merge_revocation_registry_deltas(command_handle, rev_reg_delta_json.as_ptr(), other_rev_reg_delta_json.as_ptr(), cb) }) } @@ -361,7 +361,7 @@ fn _prover_create_master_secret(command_handle: CommandHandle, wallet_handle: Wa let master_secret_id_str = opt_c_str!(master_secret_id); ErrorCode::from(unsafe { - anoncreds::indy_prover_create_master_secret(command_handle, wallet_handle, opt_c_ptr!(master_secret_id, master_secret_id_str), cb) + anoncreds::indy_prover_create_master_secret(command_handle, wallet_handle, opt_c_ptr!(master_secret_id, master_secret_id_str), cb) }) } @@ -392,7 +392,7 @@ fn _prover_get_credential(command_handle: CommandHandle, wallet_handle: WalletHa let cred_id = c_str!(cred_id); ErrorCode::from(unsafe { - anoncreds::indy_prover_get_credential(command_handle, wallet_handle, cred_id.as_ptr(), cb) + anoncreds::indy_prover_get_credential(command_handle, wallet_handle, cred_id.as_ptr(), cb) }) } @@ -413,7 +413,7 @@ fn _prover_delete_credential(command_handle: CommandHandle, wallet_handle: Walle let cred_id = c_str!(cred_id); ErrorCode::from(unsafe { - anoncreds::indy_prover_delete_credential(command_handle, wallet_handle, cred_id.as_ptr(), cb) + anoncreds::indy_prover_delete_credential(command_handle, wallet_handle, cred_id.as_ptr(), cb) }) } @@ -457,7 +457,7 @@ fn _prover_create_credential_req(command_handle: CommandHandle, wallet_handle: W let master_secret_id = c_str!(master_secret_id); ErrorCode::from(unsafe { - anoncreds::indy_prover_create_credential_req(command_handle, wallet_handle, prover_did.as_ptr(), cred_offer_json.as_ptr(), cred_def_json.as_ptr(), master_secret_id.as_ptr(), cb) + anoncreds::indy_prover_create_credential_req(command_handle, wallet_handle, prover_did.as_ptr(), cred_offer_json.as_ptr(), cred_def_json.as_ptr(), master_secret_id.as_ptr(), cb) }) } @@ -504,7 +504,7 @@ fn _prover_store_credential(command_handle: CommandHandle, wallet_handle: Wallet let rev_reg_def_json_str = opt_c_str!(rev_reg_def_json); ErrorCode::from(unsafe { - anoncreds::indy_prover_store_credential(command_handle, wallet_handle, opt_c_ptr!(cred_id, cred_id_str), cred_req_metadata_json.as_ptr(), cred_json.as_ptr(), cred_def_json.as_ptr(), opt_c_ptr!(rev_reg_def_json, rev_reg_def_json_str), cb) + anoncreds::indy_prover_store_credential(command_handle, wallet_handle, opt_c_ptr!(cred_id, cred_id_str), cred_req_metadata_json.as_ptr(), cred_json.as_ptr(), cred_def_json.as_ptr(), opt_c_ptr!(rev_reg_def_json, rev_reg_def_json_str), cb) }) } @@ -544,7 +544,7 @@ fn _prover_get_credentials(command_handle: CommandHandle, wallet_handle: WalletH let filter_json_str = opt_c_str!(filter_json); ErrorCode::from(unsafe { - anoncreds::indy_prover_get_credentials(command_handle, wallet_handle, opt_c_ptr!(filter_json, filter_json_str), cb) + anoncreds::indy_prover_get_credentials(command_handle, wallet_handle, opt_c_ptr!(filter_json, filter_json_str), cb) }) } @@ -575,7 +575,7 @@ fn _prover_search_credentials(command_handle: CommandHandle, wallet_handle: Wall let query_json_str = opt_c_str!(query_json); ErrorCode::from(unsafe { - anoncreds::indy_prover_search_credentials(command_handle, wallet_handle, opt_c_ptr!(query_json, query_json_str), cb) + anoncreds::indy_prover_search_credentials(command_handle, wallet_handle, opt_c_ptr!(query_json, query_json_str), cb) }) } @@ -604,9 +604,8 @@ pub fn prover_fetch_credentials(search_handle: SearchHandle, count: usize) -> Bo } fn _prover_fetch_credentials(command_handle: CommandHandle, search_handle: SearchHandle, count: usize, cb: Option) -> ErrorCode { - ErrorCode::from(unsafe { - anoncreds::indy_prover_fetch_credentials(command_handle, search_handle, count, cb) + anoncreds::indy_prover_fetch_credentials(command_handle, search_handle, count, cb) }) } @@ -623,9 +622,8 @@ pub fn prover_close_credentials_search(search_handle: SearchHandle) -> Box) -> ErrorCode { - ErrorCode::from(unsafe { - anoncreds::indy_prover_close_credentials_search(command_handle, search_handle, cb) + anoncreds::indy_prover_close_credentials_search(command_handle, search_handle, cb) }) } @@ -716,7 +714,7 @@ fn _prover_get_credentials_for_proof_req(command_handle: CommandHandle, wallet_h let proof_request_json = c_str!(proof_request_json); ErrorCode::from(unsafe { - anoncreds::indy_prover_get_credentials_for_proof_req(command_handle, wallet_handle, proof_request_json.as_ptr(), cb) + anoncreds::indy_prover_get_credentials_for_proof_req(command_handle, wallet_handle, proof_request_json.as_ptr(), cb) }) } @@ -802,7 +800,7 @@ fn _prover_search_credentials_for_proof_req(command_handle: CommandHandle, let extra_query_json_str = opt_c_str!(extra_query_json); ErrorCode::from(unsafe { - anoncreds::indy_prover_search_credentials_for_proof_req(command_handle, wallet_handle, proof_request_json.as_ptr(), opt_c_ptr!(extra_query_json, extra_query_json_str), cb) + anoncreds::indy_prover_search_credentials_for_proof_req(command_handle, wallet_handle, proof_request_json.as_ptr(), opt_c_ptr!(extra_query_json, extra_query_json_str), cb) }) } @@ -849,7 +847,7 @@ fn _prover_fetch_credentials_for_proof_req(command_handle: CommandHandle, search let item_referent = c_str!(item_referent); ErrorCode::from(unsafe { - anoncreds::indy_prover_fetch_credentials_for_proof_req(command_handle, search_handle, item_referent.as_ptr(), count, cb) + anoncreds::indy_prover_fetch_credentials_for_proof_req(command_handle, search_handle, item_referent.as_ptr(), count, cb) }) } @@ -866,9 +864,8 @@ pub fn prover_close_credentials_search_for_proof_req(search_handle: SearchHandle } fn _prover_close_credentials_search_for_proof_req(command_handle: CommandHandle, search_handle: SearchHandle, cb: Option) -> ErrorCode { - ErrorCode::from(unsafe { - anoncreds::indy_prover_close_credentials_search_for_proof_req(command_handle, search_handle, cb) + anoncreds::indy_prover_close_credentials_search_for_proof_req(command_handle, search_handle, cb) }) } @@ -1016,7 +1013,7 @@ fn _prover_create_proof(command_handle: CommandHandle, wallet_handle: WalletHand let rev_states_json = c_str!(rev_states_json); ErrorCode::from(unsafe { - anoncreds::indy_prover_create_proof(command_handle, wallet_handle, proof_req_json.as_ptr(), requested_credentials_json.as_ptr(), master_secret_id.as_ptr(), schemas_json.as_ptr(), credential_defs_json.as_ptr(), rev_states_json.as_ptr(), cb) + anoncreds::indy_prover_create_proof(command_handle, wallet_handle, proof_req_json.as_ptr(), requested_credentials_json.as_ptr(), master_secret_id.as_ptr(), schemas_json.as_ptr(), credential_defs_json.as_ptr(), rev_states_json.as_ptr(), cb) }) } @@ -1154,7 +1151,7 @@ fn _create_revocation_state(command_handle: CommandHandle, blob_storage_reader_h let cred_rev_id = c_str!(cred_rev_id); ErrorCode::from(unsafe { - anoncreds::indy_create_revocation_state(command_handle, blob_storage_reader_handle, rev_reg_def_json.as_ptr(), rev_reg_delta_json.as_ptr(), timestamp, cred_rev_id.as_ptr(), cb) + anoncreds::indy_create_revocation_state(command_handle, blob_storage_reader_handle, rev_reg_def_json.as_ptr(), rev_reg_delta_json.as_ptr(), timestamp, cred_rev_id.as_ptr(), cb) }) } @@ -1191,6 +1188,6 @@ fn _update_revocation_state(command_handle: CommandHandle, blob_storage_reader_h let cred_rev_id = c_str!(cred_rev_id); ErrorCode::from(unsafe { - anoncreds::indy_update_revocation_state(command_handle, blob_storage_reader_handle, rev_state_json.as_ptr(), rev_reg_def_json.as_ptr(), rev_reg_delta_json.as_ptr(), timestamp, cred_rev_id.as_ptr(), cb) + anoncreds::indy_update_revocation_state(command_handle, blob_storage_reader_handle, rev_state_json.as_ptr(), rev_reg_def_json.as_ptr(), rev_reg_delta_json.as_ptr(), timestamp, cred_rev_id.as_ptr(), cb) }) } diff --git a/wrappers/rust/src/blob_storage.rs b/wrappers/rust/src/blob_storage.rs index e2312f1247..14f52035d2 100644 --- a/wrappers/rust/src/blob_storage.rs +++ b/wrappers/rust/src/blob_storage.rs @@ -8,7 +8,7 @@ use ffi::blob_storage; use ffi::ResponseI32CB; use utils::callbacks::{ClosureHandler, ResultHandler}; -use ffi::{IndyHandle, CommandHandle}; +use {IndyHandle, CommandHandle}; pub fn open_reader(xtype: &str, config_json: &str) -> Box> { let (receiver, command_handle, cb) = ClosureHandler::cb_ec_handle(); diff --git a/wrappers/rust/src/cache.rs b/wrappers/rust/src/cache.rs index 614fd5fc89..97b8bf16e3 100644 --- a/wrappers/rust/src/cache.rs +++ b/wrappers/rust/src/cache.rs @@ -8,7 +8,7 @@ use utils::callbacks::{ClosureHandler, ResultHandler}; use ffi::cache; use ffi::{ResponseEmptyCB, ResponseStringCB}; -use ffi::{WalletHandle, CommandHandle, PoolHandle}; +use {WalletHandle, CommandHandle, PoolHandle}; /// Get schema json data for specified schema id. /// If data is present inside of cache, cached data is returned. diff --git a/wrappers/rust/src/crypto.rs b/wrappers/rust/src/crypto.rs index d115475354..dc164c9c5d 100644 --- a/wrappers/rust/src/crypto.rs +++ b/wrappers/rust/src/crypto.rs @@ -12,7 +12,7 @@ use std::ptr::null; use {ErrorCode, IndyError}; use utils::callbacks::{ClosureHandler, ResultHandler}; -use ffi::{WalletHandle, CommandHandle}; +use {WalletHandle, CommandHandle}; /// Creates key pair in wallet /// # Arguments diff --git a/wrappers/rust/src/did.rs b/wrappers/rust/src/did.rs index 9e50aef998..992c5c20f8 100644 --- a/wrappers/rust/src/did.rs +++ b/wrappers/rust/src/did.rs @@ -10,7 +10,7 @@ use ffi::{ResponseEmptyCB, ResponseStringStringCB}; use utils::callbacks::{ClosureHandler, ResultHandler}; -use ffi::{CommandHandle, WalletHandle, PoolHandle}; +use {CommandHandle, WalletHandle, PoolHandle}; /// Creates keys (signing and encryption keys) for a new /// DID (owned by the caller of the library). diff --git a/wrappers/rust/src/ledger.rs b/wrappers/rust/src/ledger.rs index 64e5e902c9..75486b605c 100644 --- a/wrappers/rust/src/ledger.rs +++ b/wrappers/rust/src/ledger.rs @@ -11,7 +11,7 @@ use ffi::{ResponseStringCB, ResponseStringStringU64CB}; use utils::callbacks::{ClosureHandler, ResultHandler}; -use ffi::{WalletHandle, CommandHandle, PoolHandle}; +use {WalletHandle, CommandHandle, PoolHandle}; /// Signs and submits request message to validator pool. /// diff --git a/wrappers/rust/src/lib.rs b/wrappers/rust/src/lib.rs index 44b155260e..9d6ba0050d 100644 --- a/wrappers/rust/src/lib.rs +++ b/wrappers/rust/src/lib.rs @@ -40,6 +40,22 @@ use std::ffi::CStr; use failure::{Backtrace, Fail}; +pub use ffi::{ + IndyHandle, + CommandHandle, + WalletHandle, + PoolHandle, + SearchHandle, + RecordHandle, + TailWriterHandle, + StorageHandle, + BlobStorageReaderHandle, + BlobStorageReaderCfgHandle, + MetadataHandle, + Timeout, + TailsWriterHandle, +}; + /// Set libindy runtime configuration. Can be optionally called to change current params. /// /// # Arguments diff --git a/wrappers/rust/src/pairwise.rs b/wrappers/rust/src/pairwise.rs index 8f34463365..4744811fcd 100644 --- a/wrappers/rust/src/pairwise.rs +++ b/wrappers/rust/src/pairwise.rs @@ -11,7 +11,7 @@ use ffi::pairwise; use ffi::{ResponseEmptyCB, ResponseStringCB, ResponseBoolCB}; -use ffi::{WalletHandle, CommandHandle}; +use {WalletHandle, CommandHandle}; pub fn is_pairwise_exists(wallet_handle: WalletHandle, their_did: &str) -> Box> { let (receiver, command_handle, cb) = ClosureHandler::cb_ec_bool(); diff --git a/wrappers/rust/src/payments.rs b/wrappers/rust/src/payments.rs index 2a8ffb303c..32a7c0c706 100644 --- a/wrappers/rust/src/payments.rs +++ b/wrappers/rust/src/payments.rs @@ -10,7 +10,7 @@ use ffi::{ResponseStringCB, ResponseStringStringCB}; use utils::callbacks::{ClosureHandler, ResultHandler}; -use ffi::{WalletHandle, CommandHandle}; +use {WalletHandle, CommandHandle}; /// Create the payment address for specified payment method /// diff --git a/wrappers/rust/src/pool.rs b/wrappers/rust/src/pool.rs index 22f728c1d9..39ec5886a9 100644 --- a/wrappers/rust/src/pool.rs +++ b/wrappers/rust/src/pool.rs @@ -11,7 +11,7 @@ use ffi::{ResponseEmptyCB, ResponseI32CB}; use futures::Future; -use ffi::{CommandHandle, PoolHandle}; +use {CommandHandle, PoolHandle}; /// Creates a new local pool ledger configuration that can be used later to connect pool nodes. /// diff --git a/wrappers/rust/src/wallet.rs b/wrappers/rust/src/wallet.rs index 916888012b..9064b53ee2 100644 --- a/wrappers/rust/src/wallet.rs +++ b/wrappers/rust/src/wallet.rs @@ -11,7 +11,7 @@ use ffi::{wallet, non_secrets}; use ffi::{ResponseEmptyCB, ResponseStringCB, ResponseI32CB}; -use ffi::{CommandHandle, WalletHandle, SearchHandle}; +use {CommandHandle, WalletHandle, SearchHandle}; /// Registers custom wallet implementation. ///