Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clippy/autofix #522

Merged
merged 2 commits into from
Jul 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion agency_client/src/api/downloaded_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,6 @@ impl DownloadedMessageEncrypted {
}

async fn _auth_decrypt_v3_message(&self, wallet_handle: WalletHandle, expected_sender_vk: &str) -> AgencyClientResult<String> {
EncryptionEnvelope::auth_unpack(wallet_handle, self.payload()?, &expected_sender_vk).await
EncryptionEnvelope::auth_unpack(wallet_handle, self.payload()?, expected_sender_vk).await
}
}
2 changes: 1 addition & 1 deletion agency_client/src/api/messaging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl AgencyClient {
.build()
);

let data = self.prepare_message_for_connection_agent(vec![message], &to_pw_vk, &agent_did, &agent_vk).await?;
let data = self.prepare_message_for_connection_agent(vec![message], to_pw_vk, agent_did, agent_vk).await?;
let response = self.post_to_agency(&data).await?;
let mut response = self.parse_response_from_agency(&response).await?;

Expand Down
6 changes: 3 additions & 3 deletions agency_client/src/api/onboarding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ impl AgencyClient {
trace!("connect >>> my_did: {}, my_vk: {}, agency_did: {}", my_did, my_vk, agency_did);
let message = Client2AgencyMessage::Connect(Connect::build(my_did, my_vk));

let mut response = self.send_message_to_agency(&message, agency_did, &agency_vk).await?;
let mut response = self.send_message_to_agency(&message, agency_did, agency_vk).await?;

let ConnectResponse { from_vk: agency_pw_vk, from_did: agency_pw_did, .. } =
match response.remove(0) {
Expand All @@ -34,7 +34,7 @@ impl AgencyClient {
let message = Client2AgencyMessage::SignUp(SignUp::build());

AgencyMockDecrypted::set_next_decrypted_response(test_constants::REGISTER_RESPONSE_DECRYPTED);
let mut response = self.send_message_to_agency(&message, &agency_pw_did, &agency_pw_vk).await?;
let mut response = self.send_message_to_agency(&message, agency_pw_did, agency_pw_vk).await?;

let _response: SignUpResponse =
match response.remove(0) {
Expand All @@ -47,7 +47,7 @@ impl AgencyClient {
async fn _create_agent(&self, agency_pw_did: &str, agency_pw_vk: &str) -> AgencyClientResult<CreateAgentResponse> {
let message = Client2AgencyMessage::CreateAgent(CreateAgent::build());
AgencyMockDecrypted::set_next_decrypted_response(test_constants::AGENT_CREATED_DECRYPTED);
let mut response = self.send_message_to_agency(&message, &agency_pw_did, &agency_pw_vk).await?;
let mut response = self.send_message_to_agency(&message, agency_pw_did, agency_pw_vk).await?;

let response: CreateAgentResponse =
match response.remove(0) {
Expand Down
6 changes: 3 additions & 3 deletions agency_client/src/httpclient.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub async fn post_message(body_content: &Vec<u8>, url: &str) -> AgencyClientResu
.send()
.await
.map_err(|err| {
AgencyClientError::from_msg(AgencyClientErrorKind::PostMessageFailed, format!("HTTP Client could not connect with {}, err: {}", url, err.to_string()))
AgencyClientError::from_msg(AgencyClientErrorKind::PostMessageFailed, format!("HTTP Client could not connect with {}, err: {}", url, err))
})?;

let content_length = response.content_length();
Expand All @@ -61,11 +61,11 @@ pub async fn post_message(body_content: &Vec<u8>, url: &str) -> AgencyClientResu
if response_status.is_success() {
Ok(payload.into_bytes())
} else {
Err(AgencyClientError::from_msg(AgencyClientErrorKind::PostMessageFailed, format!("POST {} failed due to non-success HTTP status: {}, response body: {}", url, response_status.to_string(), payload)))
Err(AgencyClientError::from_msg(AgencyClientErrorKind::PostMessageFailed, format!("POST {} failed due to non-success HTTP status: {}, response body: {}", url, response_status, payload)))
}
}
Err(error) => {
Err(AgencyClientError::from_msg(AgencyClientErrorKind::PostMessageFailed, format!("POST {} failed because response could not be decoded as utf-8, HTTP status: {}, content-length header: {:?}, error: {:?}", url, response_status.to_string(), content_length, error)))
Err(AgencyClientError::from_msg(AgencyClientErrorKind::PostMessageFailed, format!("POST {} failed because response could not be decoded as utf-8, HTTP status: {}, content-length header: {:?}, error: {:?}", url, response_status, content_length, error)))
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion agency_client/src/internal/messaging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ impl AgencyClient {

pub async fn send_message_to_agency(&self, message: &Client2AgencyMessage, did: &str, verkey: &str) -> AgencyClientResult<Vec<Client2AgencyMessage>> {
trace!("send_message_to_agency >>> message: ..., did: {}", did);
let data = self.prepare_message_for_agency(message, &did, verkey).await?;
let data = self.prepare_message_for_agency(message, did, verkey).await?;
let response = self.post_to_agency(&data).await?;
self.parse_response_from_agency(&response).await
}
Expand Down
2 changes: 1 addition & 1 deletion agency_client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl std::string::ToString for MessageStatusCode {
impl Serialize for MessageStatusCode {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: Serializer {
let value = self.to_string();
Value::String(value.to_string()).serialize(serializer)
Value::String(value).serialize(serializer)
}
}

Expand Down
2 changes: 1 addition & 1 deletion agency_client/src/messages/message_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl From<String> for MessageFamilies {
"onboarding" => MessageFamilies::Onboarding,
"pairwise" => MessageFamilies::Pairwise,
"configs" => MessageFamilies::Configs,
family @ _ => MessageFamilies::Unknown(family.to_string())
family => MessageFamilies::Unknown(family.to_string())
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion agency_client/src/messages/update_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl UpdateMessageStatusByConnectionsBuilder {
}

pub fn status_code(&mut self, code: MessageStatusCode) -> AgencyClientResult<&mut Self> {
self.status_code = Some(code.clone());
self.status_code = Some(code);
Ok(self)
}

Expand Down
6 changes: 3 additions & 3 deletions agency_client/src/testing/mocking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl HttpClientMockResponse {
}

pub fn has_response() -> bool {
HTTPCLIENT_MOCK_RESPONSES.lock().unwrap().responses.len() > 0
!HTTPCLIENT_MOCK_RESPONSES.lock().unwrap().responses.is_empty()
}

pub fn get_response() -> AgencyClientResult<Vec<u8>> {
Expand Down Expand Up @@ -77,7 +77,7 @@ impl AgencyMockDecrypted {
}

pub fn has_decrypted_mock_responses() -> bool {
AGENCY_MOCK_DECRYPTED_RESPONSES.lock().unwrap().responses.len() > 0
!AGENCY_MOCK_DECRYPTED_RESPONSES.lock().unwrap().responses.is_empty()
}

pub fn set_next_decrypted_message(message: &str) {
Expand All @@ -92,7 +92,7 @@ impl AgencyMockDecrypted {
}

pub fn has_decrypted_mock_messages() -> bool {
AGENCY_MOCK_DECRYPTED_MESSAGES.lock().unwrap().messages.len() > 0
!AGENCY_MOCK_DECRYPTED_MESSAGES.lock().unwrap().messages.is_empty()
}

pub fn clear_mocks() {
Expand Down
4 changes: 2 additions & 2 deletions agency_client/src/testing/test_constants.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pub const CREATE_KEYS_V2_RESPONSE: &'static [u8; 343] = &[123, 34, 109, 101, 115, 115, 97, 103, 101, 34, 58, 34, 123, 92, 34, 64, 116, 121, 112, 101, 92, 34, 58, 92, 34, 100, 105, 100, 58, 115, 111, 118, 58, 49, 50, 51, 52, 53, 54, 55, 56, 57, 97, 98, 99, 100, 101, 102, 103, 104, 105, 49, 50, 51, 52, 59, 115, 112, 101, 99, 47, 99, 111, 110, 110, 101, 99, 116, 105, 110, 103, 47, 48, 46, 54, 47, 75, 69, 89, 95, 67, 82, 69, 65, 84, 69, 68, 92, 34, 44, 92, 34, 119, 105, 116, 104, 80, 97, 105, 114, 119, 105, 115, 101, 68, 73, 68, 92, 34, 58, 92, 34, 77, 78, 101, 112, 101, 83, 87, 116, 71, 102, 104, 110, 118, 56, 106, 76, 66, 49, 115, 70, 90, 67, 92, 34, 44, 92, 34, 119, 105, 116, 104, 80, 97, 105, 114, 119, 105, 115, 101, 68, 73, 68, 86, 101, 114, 75, 101, 121, 92, 34, 58, 92, 34, 67, 55, 51, 77, 82, 110, 110, 115, 52, 113, 85, 106, 82, 53, 78, 52, 76, 82, 119, 84, 121, 105, 88, 86, 80, 75, 80, 114, 65, 53, 113, 52, 76, 67, 84, 56, 80, 90, 122, 120, 86, 100, 116, 57, 92, 34, 125, 34, 44, 34, 114, 101, 99, 105, 112, 105, 101, 110, 116, 95, 118, 101, 114, 107, 101, 121, 34, 58, 34, 50, 112, 70, 109, 113, 97, 98, 119, 75, 82, 82, 109, 80, 54, 76, 117, 67, 99, 121, 65, 70, 101, 107, 56, 77, 109, 68, 75, 107, 107, 102, 100, 72, 111, 100, 116, 57, 103, 90, 49, 67, 88, 74, 52, 34, 44, 34, 115, 101, 110, 100, 101, 114, 95, 118, 101, 114, 107, 101, 121, 34, 58, 34, 65, 66, 117, 89, 121, 84, 87, 90, 120, 113, 53, 88, 98, 105, 54, 90, 69, 119, 119, 121, 49, 97, 51, 69, 88, 51, 90, 68, 56, 100, 105, 112, 115, 109, 102, 106, 81, 53, 75, 116, 71, 116, 115, 120, 34, 125];
pub const UPDATE_MESSAGES_RESPONSE: &'static [u8; 147] = &[129, 167, 98, 117, 110, 100, 108, 101, 100, 145, 220, 0, 119, 208, 130, 208, 165, 64, 116, 121, 112, 101, 208, 130, 208, 164, 110, 97, 109, 101, 208, 187, 77, 83, 71, 95, 83, 84, 65, 84, 85, 83, 95, 85, 80, 68, 65, 84, 69, 68, 95, 66, 89, 95, 67, 79, 78, 78, 83, 208, 163, 118, 101, 114, 208, 163, 49, 46, 48, 208, 178, 117, 112, 100, 97, 116, 101, 100, 85, 105, 100, 115, 66, 121, 67, 111, 110, 110, 115, 208, 145, 208, 130, 208, 171, 112, 97, 105, 114, 119, 105, 115, 101, 68, 73, 68, 208, 182, 55, 57, 82, 78, 82, 113, 77, 87, 52, 72, 106, 107, 97, 111, 98, 101, 72, 105, 69, 77, 110, 101, 208, 164, 117, 105, 100, 115, 208, 145, 208, 167, 111, 103, 109, 49, 121, 50, 102];
pub const CREATE_KEYS_V2_RESPONSE: &[u8; 343] = &[123, 34, 109, 101, 115, 115, 97, 103, 101, 34, 58, 34, 123, 92, 34, 64, 116, 121, 112, 101, 92, 34, 58, 92, 34, 100, 105, 100, 58, 115, 111, 118, 58, 49, 50, 51, 52, 53, 54, 55, 56, 57, 97, 98, 99, 100, 101, 102, 103, 104, 105, 49, 50, 51, 52, 59, 115, 112, 101, 99, 47, 99, 111, 110, 110, 101, 99, 116, 105, 110, 103, 47, 48, 46, 54, 47, 75, 69, 89, 95, 67, 82, 69, 65, 84, 69, 68, 92, 34, 44, 92, 34, 119, 105, 116, 104, 80, 97, 105, 114, 119, 105, 115, 101, 68, 73, 68, 92, 34, 58, 92, 34, 77, 78, 101, 112, 101, 83, 87, 116, 71, 102, 104, 110, 118, 56, 106, 76, 66, 49, 115, 70, 90, 67, 92, 34, 44, 92, 34, 119, 105, 116, 104, 80, 97, 105, 114, 119, 105, 115, 101, 68, 73, 68, 86, 101, 114, 75, 101, 121, 92, 34, 58, 92, 34, 67, 55, 51, 77, 82, 110, 110, 115, 52, 113, 85, 106, 82, 53, 78, 52, 76, 82, 119, 84, 121, 105, 88, 86, 80, 75, 80, 114, 65, 53, 113, 52, 76, 67, 84, 56, 80, 90, 122, 120, 86, 100, 116, 57, 92, 34, 125, 34, 44, 34, 114, 101, 99, 105, 112, 105, 101, 110, 116, 95, 118, 101, 114, 107, 101, 121, 34, 58, 34, 50, 112, 70, 109, 113, 97, 98, 119, 75, 82, 82, 109, 80, 54, 76, 117, 67, 99, 121, 65, 70, 101, 107, 56, 77, 109, 68, 75, 107, 107, 102, 100, 72, 111, 100, 116, 57, 103, 90, 49, 67, 88, 74, 52, 34, 44, 34, 115, 101, 110, 100, 101, 114, 95, 118, 101, 114, 107, 101, 121, 34, 58, 34, 65, 66, 117, 89, 121, 84, 87, 90, 120, 113, 53, 88, 98, 105, 54, 90, 69, 119, 119, 121, 49, 97, 51, 69, 88, 51, 90, 68, 56, 100, 105, 112, 115, 109, 102, 106, 81, 53, 75, 116, 71, 116, 115, 120, 34, 125];
pub const UPDATE_MESSAGES_RESPONSE: &[u8; 147] = &[129, 167, 98, 117, 110, 100, 108, 101, 100, 145, 220, 0, 119, 208, 130, 208, 165, 64, 116, 121, 112, 101, 208, 130, 208, 164, 110, 97, 109, 101, 208, 187, 77, 83, 71, 95, 83, 84, 65, 84, 85, 83, 95, 85, 80, 68, 65, 84, 69, 68, 95, 66, 89, 95, 67, 79, 78, 78, 83, 208, 163, 118, 101, 114, 208, 163, 49, 46, 48, 208, 178, 117, 112, 100, 97, 116, 101, 100, 85, 105, 100, 115, 66, 121, 67, 111, 110, 110, 115, 208, 145, 208, 130, 208, 171, 112, 97, 105, 114, 119, 105, 115, 101, 68, 73, 68, 208, 182, 55, 57, 82, 78, 82, 113, 77, 87, 52, 72, 106, 107, 97, 111, 98, 101, 72, 105, 69, 77, 110, 101, 208, 164, 117, 105, 100, 115, 208, 145, 208, 167, 111, 103, 109, 49, 121, 50, 102];
pub const CONNECTED_RESPONSE_DECRYPTED: &str = r#"{"@type":"did:sov:123456789abcdefghi1234;spec/onboarding/1.0/CONNECTED","withPairwiseDID":"XSasL1cESeSJ2v9wMYeXBf","withPairwiseDIDVerKey":"HbJb8uKp4mtjhnNknP66GgmUMYta6XArNaA4WJDEyyv9"}"#;
pub const REGISTER_RESPONSE_DECRYPTED: &str = r#"{"@type":"did:sov:123456789abcdefghi1234;spec/onboarding/1.0/SIGNED_UP"}"#;
pub const AGENT_CREATED_DECRYPTED: &str = r#"{"@type":"did:sov:123456789abcdefghi1234;spec/onboarding/1.0/AGENT_CREATED","withPairwiseDID":"DnEpUQJLupa5rKPkrKUpFd","withPairwiseDIDVerKey":"7y118tRW2EMJn18qs9MY5NJWYW2PLwV5QpaLyfoLHtgF"}"#;
2 changes: 1 addition & 1 deletion agency_client/src/utils/error_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ pub fn kind_to_error_message(kind: &AgencyClientErrorKind) -> String {
AgencyClientErrorKind::InvalidHttpResponse => "Invalid HTTP response.".into(),
AgencyClientErrorKind::CreateAgent => "Failed to create agency client".into(),
AgencyClientErrorKind::UnknownLibndyError => "Unknown libindy error".into(),
AgencyClientErrorKind::LibndyError(e) => format!("Libindy error with code {}", e).into(),
AgencyClientErrorKind::LibndyError(e) => format!("Libindy error with code {}", e),
}
}
4 changes: 2 additions & 2 deletions agency_client/src/utils/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ lazy_static! {
}

pub fn is_fully_qualified(entity: &str) -> bool {
REGEX.is_match(&entity)
REGEX.is_match(entity)
}

pub fn validate_did(did: &str) -> AgencyClientResult<String> {
Expand All @@ -23,7 +23,7 @@ pub fn validate_did(did: &str) -> AgencyClientResult<String> {
match check_did.from_base58() {
Ok(ref x) if x.len() == 16 => Ok(check_did),
Ok(_) => {
return Err(AgencyClientError::from_msg(AgencyClientErrorKind::InvalidDid, "Invalid DID length"));
Err(AgencyClientError::from_msg(AgencyClientErrorKind::InvalidDid, "Invalid DID length"))
}
Err(x) => {
warn!("Err({:?})", x);
Expand Down
2 changes: 1 addition & 1 deletion aries_vcx/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ pub fn err_msg<D>(kind: VcxErrorKind, msg: D) -> VcxError

impl From<VcxErrorKind> for VcxError {
fn from(kind: VcxErrorKind) -> VcxError {
VcxError::from_msg(kind, crate::utils::error::error_message(&kind.clone().into()))
VcxError::from_msg(kind, crate::utils::error::error_message(&kind.into()))
}
}

Expand Down
12 changes: 6 additions & 6 deletions aries_vcx/src/global/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ pub static CONFIG_LOG_CONFIG: &str = "log_config";
pub static CONFIG_EXPORTED_WALLET_PATH: &str = "exported_wallet_path";
pub static CONFIG_WALLET_BACKUP_KEY: &str = "backup_key";
pub static CONFIG_WALLET_KEY: &str = "wallet_key";
pub static CONFIG_WALLET_NAME: &'static str = "wallet_name";
pub static CONFIG_WALLET_TYPE: &'static str = "wallet_type";
pub static CONFIG_WALLET_KEY_DERIVATION: &'static str = "wallet_key_derivation";
pub static CONFIG_PROTOCOL_VERSION: &'static str = "protocol_version";
pub static CONFIG_TXN_AUTHOR_AGREEMENT: &'static str = "author_agreement";
pub static CONFIG_POOL_CONFIG: &'static str = "pool_config";
pub static CONFIG_WALLET_NAME: &str = "wallet_name";
pub static CONFIG_WALLET_TYPE: &str = "wallet_type";
pub static CONFIG_WALLET_KEY_DERIVATION: &str = "wallet_key_derivation";
pub static CONFIG_PROTOCOL_VERSION: &str = "protocol_version";
pub static CONFIG_TXN_AUTHOR_AGREEMENT: &str = "author_agreement";
pub static CONFIG_POOL_CONFIG: &str = "pool_config";
pub static CONFIG_DID_METHOD: &str = "did_method";
// proprietary or aries
pub static CONFIG_ACTORS: &str = "actors";
Expand Down
14 changes: 7 additions & 7 deletions aries_vcx/src/handlers/connection/cloud_agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl CloudAgentInfo {
// todo: implement this in agency_client
pub fn routing_keys(&self, agency_client: &AgencyClient) -> VcxResult<Vec<String>> {
let agency_vk = agency_client.get_agency_vk();
Ok(vec![self.agent_vk.to_string(), agency_vk.to_string()])
Ok(vec![self.agent_vk.to_string(), agency_vk])
}

pub async fn update_message_status(&self, agency_client: &AgencyClient, pairwise_info: &PairwiseInfo, uid: String) -> VcxResult<()> {
Expand Down Expand Up @@ -118,28 +118,28 @@ impl CloudAgentInfo {
let message = messages
.pop()
.ok_or(VcxError::from_msg(VcxErrorKind::InvalidMessages, format!("Message not found for id: {:?}", msg_id)))?;
let message = self.decrypt_decode_message(agency_client.get_wallet_handle(), &message, &expected_sender_vk).await?;
let message = self.decrypt_decode_message(agency_client.get_wallet_handle(), &message, expected_sender_vk).await?;
Ok(message)
}

async fn decrypt_decode_messages(&self, wallet_handle: WalletHandle, messages: &Vec<DownloadedMessageEncrypted>, expected_sender_vk: &str) -> VcxResult<HashMap<String, A2AMessage>> {
let mut a2a_messages: HashMap<String, A2AMessage> = HashMap::new();
for message in messages {
a2a_messages.insert(message.uid.clone(), self.decrypt_decode_message(wallet_handle, &message, expected_sender_vk).await?);
a2a_messages.insert(message.uid.clone(), self.decrypt_decode_message(wallet_handle, message, expected_sender_vk).await?);
}
return Ok(a2a_messages);
Ok(a2a_messages)
}

async fn decrypt_decode_messages_noauth(&self, wallet_handle: WalletHandle, messages: &Vec<DownloadedMessageEncrypted>) -> VcxResult<HashMap<String, A2AMessage>> {
let mut a2a_messages: HashMap<String, A2AMessage> = HashMap::new();
for message in messages {
a2a_messages.insert(message.uid.clone(), self.decrypt_decode_message_noauth(wallet_handle, &message).await?);
a2a_messages.insert(message.uid.clone(), self.decrypt_decode_message_noauth(wallet_handle, message).await?);
}
return Ok(a2a_messages);
Ok(a2a_messages)
}

async fn decrypt_decode_message(&self, wallet_handle: WalletHandle, message: &DownloadedMessageEncrypted, expected_sender_vk: &str) -> VcxResult<A2AMessage> {
EncryptionEnvelope::auth_unpack(wallet_handle, message.payload()?, &expected_sender_vk).await
EncryptionEnvelope::auth_unpack(wallet_handle, message.payload()?, expected_sender_vk).await
}

async fn decrypt_decode_message_noauth(&self, wallet_handle: WalletHandle, message: &DownloadedMessageEncrypted) -> VcxResult<A2AMessage> {
Expand Down