Skip to content

Commit

Permalink
Merge branch 'master' into feature/vcx-v3-delete-credential
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrik-Stas authored Jun 23, 2020
2 parents 78d6b69 + 1b9a5db commit ec41681
Show file tree
Hide file tree
Showing 31 changed files with 392 additions and 356 deletions.
3 changes: 1 addition & 2 deletions cli/src/command_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use unescape::unescape;
use std::cell::RefCell;
use std::collections::BTreeMap;
use std::collections::HashMap;
use std::error::Error;

use linefeed::{Reader, ReadResult};

Expand Down Expand Up @@ -868,7 +867,7 @@ impl CommandExecutor {
}
}
Err(err) => {
println_err!("{}", err.description().to_string());
println_err!("{}", err.to_string());
println!("Please enter value for {}:", param);
}
}
Expand Down
3 changes: 1 addition & 2 deletions cli/src/utils/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ extern crate log4rs;
extern crate log;
extern crate libc;

use std::error::Error;
use indy;

pub struct IndyCliLogger;

impl IndyCliLogger {
pub fn init(path: &str) -> Result<(), String> {
log4rs::init_file(path, Default::default())
.map_err(|err| format!("Cannot init Indy CLI logger: {}", err.description()))?;
.map_err(|err| format!("Cannot init Indy CLI logger: {}", err.to_string()))?;

indy::logger::set_logger(log::logger())
.map_err(|_| "Cannot init Libindy logger".to_string())
Expand Down
15 changes: 1 addition & 14 deletions libindy/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions libindy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ only_high_cases = []
fatal_warnings = []

[dependencies]
env_logger = "0.6.2"
env_logger = "0.7"
etcommon-rlp = "0.2.4"
failure = "0.1.6"
failure = "0.1.7"
hex = "0.3.2"
libc = "0.2.66"
log = "0.4.8"
Expand All @@ -55,7 +55,7 @@ regex = "1.2.1"
indy-api-types = { path = "./indy-api-types"}
indy-utils = { path = "./indy-utils"}
indy-wallet = { path = "./indy-wallet"}
quote = "=1.0.2"
quote = "=1.0.7"

[dependencies.uuid]
version = "0.7.4"
Expand Down
5 changes: 1 addition & 4 deletions libindy/mac.build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,7 @@ if [[ "$OSTYPE" == "darwin"* ]]; then
export CARGO_INCREMENTAL=1
export RUST_LOG=indy=trace
export RUST_TEST_THREADS=1
for version in `ls -t /usr/local/Cellar/openssl/`; do
export OPENSSL_DIR=/usr/local/Cellar/openssl/$version
break
done
export OPENSSL_DIR=/usr/local/opt/`ls /usr/local/opt/ | grep openssl | sort | tail -1`
cargo build
export LIBRARY_PATH=$(pwd)/target/debug
cd ../cli
Expand Down
4 changes: 2 additions & 2 deletions vcx/libvcx/src/api/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -803,13 +803,13 @@ pub extern fn vcx_connection_send_message(command_handle: CommandHandle,
msg: *const c_char,
send_msg_options: *const c_char,
cb: Option<extern fn(xcommand_handle: CommandHandle, err: u32, msg_id: *const c_char)>) -> u32 {
info!("vcx_message_send >>>");
info!("vcx_connection_send_message >>>");

check_useful_c_callback!(cb, VcxErrorKind::InvalidOption);
check_useful_c_str!(msg, VcxErrorKind::InvalidOption);
check_useful_c_str!(send_msg_options, VcxErrorKind::InvalidOption);

trace!("vcx_message_send(command_handle: {}, connection_handle: {}, msg: {}, send_msg_options: {})",
trace!("vcx_connection_send_message(command_handle: {}, connection_handle: {}, msg: {}, send_msg_options: {})",
command_handle, connection_handle, msg, send_msg_options);

spawn(move || {
Expand Down
2 changes: 1 addition & 1 deletion vcx/libvcx/src/api/disclosed_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use error::prelude::*;
use indy_sys::CommandHandle;

/*
The API represents an Prover side in credential presentation process.
APIs in this module are called by a prover throughout the request-proof-and-verify process.
Assumes that pairwise connection between Verifier and Prover is already established.
# State
Expand Down
13 changes: 6 additions & 7 deletions vcx/libvcx/src/api/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use error::prelude::*;
use indy_sys::CommandHandle;

/*
The API represents an Verifier side in credential presentation process.
APIs in this module are called by a verifier throughout the request-proof-and-verify process.
Assumes that pairwise connection between Verifier and Prover is already established.
# State
Expand Down Expand Up @@ -557,11 +557,6 @@ pub extern fn vcx_proof_get_request_msg(command_handle: CommandHandle,
}


/// Todo: This api should remove the connection_handle!! It is not being used within the code. I assume
/// the only reason it still has it as an input was to not break it for existing users. vcx_get_proof_msg
/// is the updated api that we should use.
/// Get Proof message
///
/// #Params
/// command_handle: command handle to map callback to user context.
///
Expand All @@ -573,10 +568,14 @@ pub extern fn vcx_proof_get_request_msg(command_handle: CommandHandle,
///
/// #Returns
/// Error code as a u32
#[deprecated(
since = "1.15.0",
note = "Use vcx_get_proof_msg() instead. This api is similar, but requires an extra parameter (connection_handle) which is unnecessary and unused in the internals."
)]
#[no_mangle]
pub extern fn vcx_get_proof(command_handle: CommandHandle,
proof_handle: u32,
_connection_handle: u32,
_unused_connection_handle: u32,
cb: Option<extern fn(xcommand_handle: CommandHandle, err: u32, proof_state:u32, response_data: *const c_char)>) -> u32 {
info!("vcx_get_proof >>>");

Expand Down
11 changes: 7 additions & 4 deletions vcx/libvcx/src/api/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use utils::threadpool::spawn;
use error::prelude::*;
use indy_sys::CommandHandle;

/// Create a new Schema object and publish correspondent record on the ledger
/// Create a new Schema object and publish corresponding record on the ledger
///
/// #Params
/// command_handle: command handle to map callback to user context.
Expand All @@ -18,13 +18,16 @@ use indy_sys::CommandHandle;
///
/// schema_name: Name of schema
///
/// version: version of schema
/// version: Version of schema. A semver-compatible value like "1.0" is encouraged.
///
/// schema_data: list of attributes that will make up the schema (the number of attributes should be less or equal than 125)
/// schema_data: A list of attributes that will make up the schema, represented
/// as a string containing a JSON array. The number of attributes should be
/// less or equal to 125, because larger arrays cause various downstream problems.
/// This limitation is an annoyance that we'd like to remove.
///
/// # Example schema_data -> "["attr1", "attr2", "attr3"]"
///
/// payment_handle: future use (currently uses any address in the wallet)
/// payment_handle: Reserved for future use (currently uses any address in the wallet)
///
/// cb: Callback that provides Schema handle and error status of request.
///
Expand Down
20 changes: 1 addition & 19 deletions vcx/libvcx/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1242,7 +1242,7 @@ impl From<(Connection, ActorDidExchangeState)> for ConnectionV3 {
}
}

use v3::messages::a2a::{A2AMessage, MessageId};
use v3::messages::a2a::A2AMessage;
use v3::messages::connection::did_doc::DidDoc;

pub fn get_messages(handle: u32) -> VcxResult<HashMap<String, A2AMessage>> {
Expand Down Expand Up @@ -1294,24 +1294,6 @@ pub fn send_message_to_self_endpoint(message: A2AMessage, did_doc: &DidDoc) -> V
ConnectionV3::send_message_to_self_endpoint(&message, did_doc)
}

pub fn add_pending_messages(handle: u32, messages: HashMap<MessageId, String>) -> VcxResult<()> {
CONNECTION_MAP.get(handle, |connection| {
match connection {
Connections::V1(_) => Err(VcxError::from(VcxErrorKind::InvalidConnectionHandle)),
Connections::V3(ref connection) => connection.add_pending_messages(messages.clone())
}
})
}

pub fn remove_pending_message(handle: u32, id: &MessageId) -> VcxResult<()> {
CONNECTION_MAP.get(handle, |connection| {
match connection {
Connections::V1(_) => Err(VcxError::from(VcxErrorKind::InvalidConnectionHandle)),
Connections::V3(ref connection) => connection.remove_pending_message(id.clone())
}
})
}

pub fn is_v3_connection(connection_handle: u32) -> VcxResult<bool> {
CONNECTION_MAP.get(connection_handle, |connection| {
match connection {
Expand Down
2 changes: 1 addition & 1 deletion vcx/libvcx/src/messages/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ pub enum PayloadTypes {

#[derive(Clone, Deserialize, Serialize, Debug, PartialEq)]
pub struct PayloadTypeV1 {
name: String,
pub name: String,
ver: String,
fmt: String,
}
Expand Down
1 change: 1 addition & 0 deletions vcx/libvcx/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ macro_rules! secret {
($val:expr) => {{ "_" }};
}

#[cfg(test)]
macro_rules! map (
{ $($key:expr => $value:expr),+ } => {
{
Expand Down
76 changes: 47 additions & 29 deletions vcx/libvcx/src/v3/handlers/connection/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use error::prelude::*;
use v3::handlers::connection::states::{DidExchangeSM, Actor, ActorDidExchangeState};
use v3::handlers::connection::messages::DidExchangeMessages;
use v3::handlers::connection::agent::AgentInfo;
use v3::messages::a2a::{A2AMessage, MessageId};
use v3::messages::a2a::A2AMessage;
use v3::messages::connection::invite::Invitation;

use std::collections::HashMap;
Expand Down Expand Up @@ -126,16 +126,11 @@ impl Connection {
pub fn update_state_with_message(&mut self, message: &str) -> VcxResult<()> {
trace!("Connection: update_state_with_message: {}", message);

let agent_info = self.agent_info().clone();

let message: Message = ::serde_json::from_str(&message)
let message: A2AMessage = ::serde_json::from_str(&message)
.map_err(|err| VcxError::from_msg(VcxErrorKind::InvalidOption,
format!("Cannot updated state with messages: Message deserialization failed: {:?}", err)))?;

let a2a_message = self.decode_message(&message)?;
self.handle_message(a2a_message.into())?;

agent_info.update_message_status(message.uid)?;
self.handle_message(message.into())?;

Ok(())
}
Expand Down Expand Up @@ -183,25 +178,22 @@ impl Connection {
AgentInfo::send_message_anonymously(message, did_doc)
}

pub fn send_generic_message(&self, message: &str, _message_options: &str) -> VcxResult<String> {
trace!("Connection::send_generic_message >>> message: {:?}", message);

let message = match ::serde_json::from_str::<A2AMessage>(message) {
Ok(A2AMessage::Generic(message)) => {
BasicMessage::create()
.set_content(message.to_string())
.set_time()
.to_a2a_message()
}
fn parse_generic_message(message: &str, _message_options: &str) -> A2AMessage {
match ::serde_json::from_str::<A2AMessage>(message) {
Ok(a2a_message) => a2a_message,
Err(_) => {
BasicMessage::create()
.set_content(message.to_string())
.set_time()
.to_a2a_message()
}
};
}
}

pub fn send_generic_message(&self, message: &str, _message_options: &str) -> VcxResult<String> {
trace!("Connection::send_generic_message >>> message: {:?}", message);

let message = Connection::parse_generic_message(message, _message_options);
self.send_message(&message).map(|_| String::new())
}

Expand All @@ -220,16 +212,6 @@ impl Connection {
Ok(())
}

pub fn add_pending_messages(&self, messages: HashMap<MessageId, String>) -> VcxResult<()> {
trace!("Connection::add_pending_messages >>> messages: {:?}", messages);
self.connection_sm.add_pending_messages(messages)
}

pub fn remove_pending_message(&self, id: MessageId) -> VcxResult<()> {
trace!("Connection::remove_pending_message >>> id: {:?}", id);
self.connection_sm.remove_pending_message(id)
}

pub fn send_discovery_features(&mut self, query: Option<String>, comment: Option<String>) -> VcxResult<()> {
trace!("Connection::send_discovery_features_query >>> query: {:?}, comment: {:?}", query, comment);
self.handle_message(DidExchangeMessages::DiscoverFeatures((query, comment)))
Expand Down Expand Up @@ -284,4 +266,40 @@ struct SideConnectionInfo {
service_endpoint: String,
#[serde(skip_serializing_if = "Option::is_none")]
protocols: Option<Vec<ProtocolDescriptor>>,
}

#[cfg(test)]
mod tests {
use v3::messages::a2a::A2AMessage;
use v3::handlers::connection::connection::Connection;

#[test]
fn test_parse_generic_message_plain_string_should_be_parsed_as_basic_msg() -> Result<(), String> {
let message = "Some plain text message";
let result = Connection::parse_generic_message(message, "");
match result {
A2AMessage::BasicMessage(basic_msg) => {
assert_eq!(basic_msg.content, message);
Ok(())
}
other => Err(format!("Result is not BasicMessage, but: {:?}", other))
}
}

#[test]
fn test_parse_generic_message_json_msg_should_be_parsed_as_generic() -> Result<(), String> {
let message = json!({
"@id": "some id",
"@type": "some type",
"content": "some content"
}).to_string();
let result = Connection::parse_generic_message(&message, "");
match result {
A2AMessage::Generic(value) => {
assert_eq!(value.to_string(), message);
Ok(())
}
other => Err(format!("Result is not Generic, but: {:?}", other))
}
}
}
21 changes: 0 additions & 21 deletions vcx/libvcx/src/v3/handlers/connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,27 +138,6 @@ pub mod tests {
::connection::update_message_status(alice.connection_handle, uid).unwrap();
}

// Pending Message
{
faber.activate();

let message = _ack();
::connection::send_message(faber.connection_handle, message.to_a2a_message()).unwrap();

alice.activate();

let messages = ::connection::get_messages(alice.connection_handle).unwrap();
assert_eq!(1, messages.len());
let uid = messages.keys().next().unwrap().clone();

::connection::add_pending_messages(alice.connection_handle, map!( message.id.clone() => uid )).unwrap();

::connection::remove_pending_message(alice.connection_handle, &message.id).unwrap();

let messages = ::connection::get_messages(alice.connection_handle).unwrap();
assert_eq!(0, messages.len());
}

// Download Messages
{
use messages::get_message::{download_messages, MessageByConnection, Message};
Expand Down
Loading

0 comments on commit ec41681

Please sign in to comment.