Skip to content

Commit

Permalink
refactor(crypto): Rename the IncomingResponse enum to AnyIncomingResp…
Browse files Browse the repository at this point in the history
…onse
  • Loading branch information
poljar committed Nov 27, 2024
1 parent 600a708 commit e99939d
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 42 deletions.
18 changes: 9 additions & 9 deletions bindings/matrix-sdk-crypto-ffi/src/responses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down Expand Up @@ -341,16 +341,16 @@ impl From<RoomMessageResponse> 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),
}
}
}
20 changes: 10 additions & 10 deletions crates/matrix-sdk-crypto/src/machine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ use crate::{
ToDeviceEvents,
},
requests::{
IncomingResponse, KeysQueryRequest, OutgoingRequest, ToDeviceRequest,
AnyIncomingResponse, KeysQueryRequest, OutgoingRequest, ToDeviceRequest,
UploadSigningKeysRequest,
},
EventEncryptionAlgorithm, Signatures,
Expand Down Expand Up @@ -579,34 +579,34 @@ impl OlmMachine {
pub async fn mark_request_as_sent<'a>(
&self,
request_id: &TransactionId,
response: impl Into<IncomingResponse<'a>>,
response: impl Into<AnyIncomingResponse<'a>>,
) -> 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?;
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
30 changes: 15 additions & 15 deletions crates/matrix-sdk-crypto/src/types/requests/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ impl From<OutgoingVerificationRequest> 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),
Expand All @@ -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)
}
}
2 changes: 1 addition & 1 deletion crates/matrix-sdk-crypto/src/verification/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down
2 changes: 1 addition & 1 deletion crates/matrix-sdk/src/encryption/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ impl Client {
pub(crate) async fn mark_request_as_sent(
&self,
request_id: &TransactionId,
response: impl Into<matrix_sdk_base::crypto::types::requests::IncomingResponse<'_>>,
response: impl Into<matrix_sdk_base::crypto::types::requests::AnyIncomingResponse<'_>>,
) -> Result<(), matrix_sdk_base::Error> {
Ok(self
.olm_machine()
Expand Down
10 changes: 5 additions & 5 deletions crates/matrix-sdk/src/sliding_sync/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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": {}
}))),
)
Expand All @@ -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: {},
Expand All @@ -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: {},
}
Expand Down Expand Up @@ -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: {},
Expand Down

0 comments on commit e99939d

Please sign in to comment.