From e99939db857ca36054c0023ef68cc181236fdee4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Wed, 27 Nov 2024 18:36:22 +0100 Subject: [PATCH] refactor(crypto): Rename the IncomingResponse enum to AnyIncomingResponse --- .../matrix-sdk-crypto-ffi/src/responses.rs | 18 +++++------ crates/matrix-sdk-crypto/src/machine/mod.rs | 20 ++++++------- .../group_sessions/share_strategy.rs | 2 +- .../src/types/requests/enums.rs | 30 +++++++++---------- .../matrix-sdk-crypto/src/verification/mod.rs | 2 +- crates/matrix-sdk/src/encryption/mod.rs | 2 +- crates/matrix-sdk/src/sliding_sync/mod.rs | 10 +++---- 7 files changed, 42 insertions(+), 42 deletions(-) diff --git a/bindings/matrix-sdk-crypto-ffi/src/responses.rs b/bindings/matrix-sdk-crypto-ffi/src/responses.rs index 071981ff073..379498a24ca 100644 --- a/bindings/matrix-sdk-crypto-ffi/src/responses.rs +++ b/bindings/matrix-sdk-crypto-ffi/src/responses.rs @@ -5,7 +5,7 @@ use std::collections::HashMap; use http::Response; use matrix_sdk_crypto::{ types::requests::{ - IncomingResponse, KeysBackupRequest, OutgoingRequest, + AnyIncomingResponse, KeysBackupRequest, OutgoingRequest, OutgoingVerificationRequest as SdkVerificationRequest, RoomMessageRequest, ToDeviceRequest, UploadSigningKeysRequest as RustUploadSigningKeysRequest, }, @@ -341,16 +341,16 @@ impl From for OwnedResponse { } } -impl<'a> From<&'a OwnedResponse> for IncomingResponse<'a> { +impl<'a> From<&'a OwnedResponse> for AnyIncomingResponse<'a> { fn from(r: &'a OwnedResponse) -> Self { match r { - OwnedResponse::KeysClaim(r) => IncomingResponse::KeysClaim(r), - OwnedResponse::KeysQuery(r) => IncomingResponse::KeysQuery(r), - OwnedResponse::KeysUpload(r) => IncomingResponse::KeysUpload(r), - OwnedResponse::ToDevice(r) => IncomingResponse::ToDevice(r), - OwnedResponse::SignatureUpload(r) => IncomingResponse::SignatureUpload(r), - OwnedResponse::KeysBackup(r) => IncomingResponse::KeysBackup(r), - OwnedResponse::RoomMessage(r) => IncomingResponse::RoomMessage(r), + OwnedResponse::KeysClaim(r) => AnyIncomingResponse::KeysClaim(r), + OwnedResponse::KeysQuery(r) => AnyIncomingResponse::KeysQuery(r), + OwnedResponse::KeysUpload(r) => AnyIncomingResponse::KeysUpload(r), + OwnedResponse::ToDevice(r) => AnyIncomingResponse::ToDevice(r), + OwnedResponse::SignatureUpload(r) => AnyIncomingResponse::SignatureUpload(r), + OwnedResponse::KeysBackup(r) => AnyIncomingResponse::KeysBackup(r), + OwnedResponse::RoomMessage(r) => AnyIncomingResponse::RoomMessage(r), } } } diff --git a/crates/matrix-sdk-crypto/src/machine/mod.rs b/crates/matrix-sdk-crypto/src/machine/mod.rs index c19b2c29a69..d5c80809b38 100644 --- a/crates/matrix-sdk-crypto/src/machine/mod.rs +++ b/crates/matrix-sdk-crypto/src/machine/mod.rs @@ -90,7 +90,7 @@ use crate::{ ToDeviceEvents, }, requests::{ - IncomingResponse, KeysQueryRequest, OutgoingRequest, ToDeviceRequest, + AnyIncomingResponse, KeysQueryRequest, OutgoingRequest, ToDeviceRequest, UploadSigningKeysRequest, }, EventEncryptionAlgorithm, Signatures, @@ -579,34 +579,34 @@ impl OlmMachine { pub async fn mark_request_as_sent<'a>( &self, request_id: &TransactionId, - response: impl Into>, + response: impl Into>, ) -> OlmResult<()> { match response.into() { - IncomingResponse::KeysUpload(response) => { + AnyIncomingResponse::KeysUpload(response) => { Box::pin(self.receive_keys_upload_response(response)).await?; } - IncomingResponse::KeysQuery(response) => { + AnyIncomingResponse::KeysQuery(response) => { Box::pin(self.receive_keys_query_response(request_id, response)).await?; } - IncomingResponse::KeysClaim(response) => { + AnyIncomingResponse::KeysClaim(response) => { Box::pin( self.inner.session_manager.receive_keys_claim_response(request_id, response), ) .await?; } - IncomingResponse::ToDevice(_) => { + AnyIncomingResponse::ToDevice(_) => { Box::pin(self.mark_to_device_request_as_sent(request_id)).await?; } - IncomingResponse::SigningKeysUpload(_) => { + AnyIncomingResponse::SigningKeysUpload(_) => { Box::pin(self.receive_cross_signing_upload_response()).await?; } - IncomingResponse::SignatureUpload(_) => { + AnyIncomingResponse::SignatureUpload(_) => { self.inner.verification_machine.mark_request_as_sent(request_id); } - IncomingResponse::RoomMessage(_) => { + AnyIncomingResponse::RoomMessage(_) => { self.inner.verification_machine.mark_request_as_sent(request_id); } - IncomingResponse::KeysBackup(_) => { + AnyIncomingResponse::KeysBackup(_) => { Box::pin(self.inner.backup_machine.mark_request_as_sent(request_id)).await?; } }; diff --git a/crates/matrix-sdk-crypto/src/session_manager/group_sessions/share_strategy.rs b/crates/matrix-sdk-crypto/src/session_manager/group_sessions/share_strategy.rs index 20ab2dfb8e8..7b3df39f41a 100644 --- a/crates/matrix-sdk-crypto/src/session_manager/group_sessions/share_strategy.rs +++ b/crates/matrix-sdk-crypto/src/session_manager/group_sessions/share_strategy.rs @@ -1368,7 +1368,7 @@ mod tests { machine .mark_request_as_sent( &TransactionId::new(), - crate::types::requests::IncomingResponse::KeysQuery(&kq_response), + crate::types::requests::AnyIncomingResponse::KeysQuery(&kq_response), ) .await .unwrap(); diff --git a/crates/matrix-sdk-crypto/src/types/requests/enums.rs b/crates/matrix-sdk-crypto/src/types/requests/enums.rs index 3be825e83ba..3da51ec62b7 100644 --- a/crates/matrix-sdk-crypto/src/types/requests/enums.rs +++ b/crates/matrix-sdk-crypto/src/types/requests/enums.rs @@ -135,7 +135,7 @@ impl From for AnyOutgoingRequest { /// Enum over all the incoming responses we need to receive. #[derive(Debug)] -pub enum IncomingResponse<'a> { +pub enum AnyIncomingResponse<'a> { /// The `/keys/upload` response, notifying us about the amount of uploaded /// one-time keys. KeysUpload(&'a KeysUploadResponse), @@ -158,44 +158,44 @@ pub enum IncomingResponse<'a> { KeysBackup(&'a KeysBackupResponse), } -impl<'a> From<&'a KeysUploadResponse> for IncomingResponse<'a> { +impl<'a> From<&'a KeysUploadResponse> for AnyIncomingResponse<'a> { fn from(response: &'a KeysUploadResponse) -> Self { - IncomingResponse::KeysUpload(response) + AnyIncomingResponse::KeysUpload(response) } } -impl<'a> From<&'a KeysBackupResponse> for IncomingResponse<'a> { +impl<'a> From<&'a KeysBackupResponse> for AnyIncomingResponse<'a> { fn from(response: &'a KeysBackupResponse) -> Self { - IncomingResponse::KeysBackup(response) + AnyIncomingResponse::KeysBackup(response) } } -impl<'a> From<&'a KeysQueryResponse> for IncomingResponse<'a> { +impl<'a> From<&'a KeysQueryResponse> for AnyIncomingResponse<'a> { fn from(response: &'a KeysQueryResponse) -> Self { - IncomingResponse::KeysQuery(response) + AnyIncomingResponse::KeysQuery(response) } } -impl<'a> From<&'a ToDeviceResponse> for IncomingResponse<'a> { +impl<'a> From<&'a ToDeviceResponse> for AnyIncomingResponse<'a> { fn from(response: &'a ToDeviceResponse) -> Self { - IncomingResponse::ToDevice(response) + AnyIncomingResponse::ToDevice(response) } } -impl<'a> From<&'a RoomMessageResponse> for IncomingResponse<'a> { +impl<'a> From<&'a RoomMessageResponse> for AnyIncomingResponse<'a> { fn from(response: &'a RoomMessageResponse) -> Self { - IncomingResponse::RoomMessage(response) + AnyIncomingResponse::RoomMessage(response) } } -impl<'a> From<&'a KeysClaimResponse> for IncomingResponse<'a> { +impl<'a> From<&'a KeysClaimResponse> for AnyIncomingResponse<'a> { fn from(response: &'a KeysClaimResponse) -> Self { - IncomingResponse::KeysClaim(response) + AnyIncomingResponse::KeysClaim(response) } } -impl<'a> From<&'a SignatureUploadResponse> for IncomingResponse<'a> { +impl<'a> From<&'a SignatureUploadResponse> for AnyIncomingResponse<'a> { fn from(response: &'a SignatureUploadResponse) -> Self { - IncomingResponse::SignatureUpload(response) + AnyIncomingResponse::SignatureUpload(response) } } diff --git a/crates/matrix-sdk-crypto/src/verification/mod.rs b/crates/matrix-sdk-crypto/src/verification/mod.rs index ebf3934b643..a9e26a2a7ed 100644 --- a/crates/matrix-sdk-crypto/src/verification/mod.rs +++ b/crates/matrix-sdk-crypto/src/verification/mod.rs @@ -748,7 +748,7 @@ pub(crate) mod tests { store::{Changes, CryptoStore, CryptoStoreWrapper, IdentityChanges, MemoryStore}, types::{ events::ToDeviceEvents, - requests::{OutgoingRequest, AnyOutgoingRequest, OutgoingVerificationRequest}, + requests::{AnyOutgoingRequest, OutgoingRequest, OutgoingVerificationRequest}, }, Account, DeviceData, OtherUserIdentityData, OwnUserIdentityData, }; diff --git a/crates/matrix-sdk/src/encryption/mod.rs b/crates/matrix-sdk/src/encryption/mod.rs index 4544f171f93..f8c7909940d 100644 --- a/crates/matrix-sdk/src/encryption/mod.rs +++ b/crates/matrix-sdk/src/encryption/mod.rs @@ -380,7 +380,7 @@ impl Client { pub(crate) async fn mark_request_as_sent( &self, request_id: &TransactionId, - response: impl Into>, + response: impl Into>, ) -> Result<(), matrix_sdk_base::Error> { Ok(self .olm_machine() diff --git a/crates/matrix-sdk/src/sliding_sync/mod.rs b/crates/matrix-sdk/src/sliding_sync/mod.rs index e0a0c536585..fee7155b94c 100644 --- a/crates/matrix-sdk/src/sliding_sync/mod.rs +++ b/crates/matrix-sdk/src/sliding_sync/mod.rs @@ -1693,7 +1693,7 @@ mod tests { #[async_test] #[cfg(feature = "e2e-encryption")] async fn test_no_pos_with_e2ee_marks_all_tracked_users_as_dirty() -> anyhow::Result<()> { - use matrix_sdk_base::crypto::types::requests::{IncomingResponse, AnyOutgoingRequest}; + use matrix_sdk_base::crypto::types::requests::{AnyIncomingResponse, AnyOutgoingRequest}; use matrix_sdk_test::ruma_response_from_json; use ruma::user_id; @@ -1723,7 +1723,7 @@ mod tests { olm_machine .mark_request_as_sent( outgoing_requests[0].request_id(), - IncomingResponse::KeysUpload(&ruma_response_from_json(&json!({ + AnyIncomingResponse::KeysUpload(&ruma_response_from_json(&json!({ "one_time_key_counts": {} }))), ) @@ -1732,7 +1732,7 @@ mod tests { olm_machine .mark_request_as_sent( outgoing_requests[1].request_id(), - IncomingResponse::KeysQuery(&ruma_response_from_json(&json!({ + AnyIncomingResponse::KeysQuery(&ruma_response_from_json(&json!({ "device_keys": { alice: {}, bob: {}, @@ -1750,7 +1750,7 @@ mod tests { olm_machine .mark_request_as_sent( outgoing_requests[0].request_id(), - IncomingResponse::KeysQuery(&ruma_response_from_json(&json!({ + AnyIncomingResponse::KeysQuery(&ruma_response_from_json(&json!({ "device_keys": { me: {}, } @@ -1799,7 +1799,7 @@ mod tests { olm_machine .mark_request_as_sent( outgoing_requests[0].request_id(), - IncomingResponse::KeysQuery(&ruma_response_from_json(&json!({ + AnyIncomingResponse::KeysQuery(&ruma_response_from_json(&json!({ "device_keys": { alice: {}, bob: {},