extern crate libc;
use api::ErrorCode;
use errors::ToErrorCode;
use commands::{Command, CommandExecutor};
use commands::signus::SignusCommand;
use utils::cstring::CStringUtils;
use self::libc::c_char;
#[no_mangle]
pub extern fn indy_create_and_store_my_did(command_handle: i32,
wallet_handle: i32,
did_json: *const c_char,
cb: Option<extern fn(xcommand_handle: i32, err: ErrorCode,
did: *const c_char,
verkey: *const c_char,
pk: *const c_char)>) -> ErrorCode {
check_useful_c_str!(did_json, ErrorCode::CommonInvalidParam3);
check_useful_c_callback!(cb, ErrorCode::CommonInvalidParam4);
let result = CommandExecutor::instance()
.send(Command::Signus(SignusCommand::CreateAndStoreMyDid(
wallet_handle,
did_json,
Box::new(move |result| {
let (err, did, verkey, pk) = result_to_err_code_3!(result, String::new(), String::new(), String::new());
let did = CStringUtils::string_to_cstring(did);
let verkey = CStringUtils::string_to_cstring(verkey);
let pk = CStringUtils::string_to_cstring(pk);
cb(command_handle, err, did.as_ptr(), verkey.as_ptr(), pk.as_ptr())
})
)));
result_to_err_code!(result)
}
#[no_mangle]
pub extern fn indy_replace_keys(command_handle: i32,
wallet_handle: i32,
did: *const c_char,
identity_json: *const c_char,
cb: Option<extern fn(xcommand_handle: i32, err: ErrorCode,
verkey: *const c_char,
pk: *const c_char)>) -> ErrorCode {
check_useful_c_str!(identity_json, ErrorCode::CommonInvalidParam3);
check_useful_c_str!(did, ErrorCode::CommonInvalidParam4);
check_useful_c_callback!(cb, ErrorCode::CommonInvalidParam5);
let result = CommandExecutor::instance()
.send(Command::Signus(SignusCommand::ReplaceKeys(
wallet_handle,
identity_json,
did,
Box::new(move |result| {
let (err, verkey, pk) = result_to_err_code_2!(result, String::new(), String::new());
let verkey = CStringUtils::string_to_cstring(verkey);
let pk = CStringUtils::string_to_cstring(pk);
cb(command_handle, err, verkey.as_ptr(), pk.as_ptr())
})
)));
result_to_err_code!(result)
}
#[no_mangle]
pub extern fn indy_store_their_did(command_handle: i32,
wallet_handle: i32,
identity_json: *const c_char,
cb: Option<extern fn(xcommand_handle: i32, err: ErrorCode)>) -> ErrorCode {
check_useful_c_str!(identity_json, ErrorCode::CommonInvalidParam3);
check_useful_c_callback!(cb, ErrorCode::CommonInvalidParam4);
let result = CommandExecutor::instance()
.send(Command::Signus(SignusCommand::StoreTheirDid(
wallet_handle,
identity_json,
Box::new(move |result| {
let err = result_to_err_code!(result);
cb(command_handle, err)
})
)));
result_to_err_code!(result)
}
#[no_mangle]
pub extern fn indy_sign(command_handle: i32,
wallet_handle: i32,
did: *const c_char,
msg: *const c_char,
cb: Option<extern fn(xcommand_handle: i32, err: ErrorCode,
signature: *const c_char)>) -> ErrorCode {
check_useful_c_str!(did, ErrorCode::CommonInvalidParam3);
check_useful_c_str!(msg, ErrorCode::CommonInvalidParam4);
check_useful_c_callback!(cb, ErrorCode::CommonInvalidParam5);
let result = CommandExecutor::instance()
.send(Command::Signus(SignusCommand::Sign(
wallet_handle,
did,
msg,
Box::new(move |result| {
let (err, signed_msg) = result_to_err_code_1!(result, String::new());
let signed_msg = CStringUtils::string_to_cstring(signed_msg);
cb(command_handle, err, signed_msg.as_ptr())
})
)));
result_to_err_code!(result)
}
#[no_mangle]
pub extern fn indy_verify_signature(command_handle: i32,
wallet_handle: i32,
pool_handle: i32,
did: *const c_char,
signed_msg: *const c_char,
cb: Option<extern fn(xcommand_handle: i32, err: ErrorCode,
valid: bool)>) -> ErrorCode {
check_useful_c_str!(did, ErrorCode::CommonInvalidParam4);
check_useful_c_str!(signed_msg, ErrorCode::CommonInvalidParam5);
check_useful_c_callback!(cb, ErrorCode::CommonInvalidParam6);
let result = CommandExecutor::instance()
.send(Command::Signus(SignusCommand::VerifySignature(
wallet_handle,
pool_handle,
did,
signed_msg,
Box::new(move |result| {
let (err, valid) = result_to_err_code_1!(result, false);
cb(command_handle, err, valid)
})
)));
result_to_err_code!(result)
}
#[no_mangle]
pub extern fn indy_encrypt(command_handle: i32,
wallet_handle: i32,
pool_handle: i32,
my_did: *const c_char,
did: *const c_char,
msg: *const c_char,
cb: Option<extern fn(xcommand_handle: i32, err: ErrorCode,
encrypted_msg: *const c_char,
nonce: *const c_char)>) -> ErrorCode {
check_useful_c_str!(my_did, ErrorCode::CommonInvalidParam4);
check_useful_c_str!(did, ErrorCode::CommonInvalidParam5);
check_useful_c_str!(msg, ErrorCode::CommonInvalidParam6);
check_useful_c_callback!(cb, ErrorCode::CommonInvalidParam7);
let result = CommandExecutor::instance()
.send(Command::Signus(SignusCommand::Encrypt(
wallet_handle,
pool_handle,
my_did,
did,
msg,
Box::new(move |result| {
let (err, encrypted_msg, nonce) = result_to_err_code_2!(result, String::new(), String::new());
let encrypted_msg = CStringUtils::string_to_cstring(encrypted_msg);
let nonce = CStringUtils::string_to_cstring(nonce);
cb(command_handle, err, encrypted_msg.as_ptr(), nonce.as_ptr())
})
)));
result_to_err_code!(result)
}
#[no_mangle]
pub extern fn indy_decrypt(command_handle: i32,
wallet_handle: i32,
my_did: *const c_char,
did: *const c_char,
encrypted_msg: *const c_char,
nonce: *const c_char,
cb: Option<extern fn(xcommand_handle: i32, err: ErrorCode,
decrypted_msg: *const c_char)>) -> ErrorCode {
check_useful_c_str!(my_did, ErrorCode::CommonInvalidParam3);
check_useful_c_str!(did, ErrorCode::CommonInvalidParam5);
check_useful_c_str!(encrypted_msg, ErrorCode::CommonInvalidParam4);
check_useful_c_str!(nonce, ErrorCode::CommonInvalidParam5);
check_useful_c_callback!(cb, ErrorCode::CommonInvalidParam6);
let result = CommandExecutor::instance()
.send(Command::Signus(SignusCommand::Decrypt(
wallet_handle,
did,
my_did,
encrypted_msg,
nonce,
Box::new(move |result| {
let (err, decrypted_msg) = result_to_err_code_1!(result, String::new());
let decrypted_msg = CStringUtils::string_to_cstring(decrypted_msg);
cb(command_handle, err, decrypted_msg.as_ptr())
})
)));
result_to_err_code!(result)
}