Skip to content

Commit

Permalink
Run cargo clippy --fix --lib in agency-client
Browse files Browse the repository at this point in the history
Signed-off-by: Patrik Stas <patrik.stas@absa.africa>
  • Loading branch information
Patrik-Stas committed Jul 22, 2022
1 parent 067670e commit 20dd20d
Show file tree
Hide file tree
Showing 10 changed files with 16 additions and 17 deletions.
3 changes: 1 addition & 2 deletions agency_client/src/agency_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ pub struct AgencyClient {

pub fn validate_mandotory_config_val<F, S, E>(val: &str, err: AgencyClientErrorKind, closure: F) -> AgencyClientResult<()>
where F: Fn(&str) -> Result<S, E> {
closure(val)
.or_else(|_| Err(AgencyClientError::from(err)))?;
closure(val).map_err(|_| AgencyClientError::from(err))?;
Ok(())
}

Expand Down
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/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
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),
}
}

0 comments on commit 20dd20d

Please sign in to comment.