Skip to content

Commit

Permalink
refactor!(crypto): Rename the OutgoingRequests enum to AnyOutgoingReq…
Browse files Browse the repository at this point in the history
…uest
  • Loading branch information
poljar committed Nov 27, 2024
1 parent a94a5f1 commit 600a708
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 44 deletions.
2 changes: 1 addition & 1 deletion bindings/matrix-sdk-crypto-ffi/src/responses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ pub enum Request {

impl From<OutgoingRequest> for Request {
fn from(r: OutgoingRequest) -> Self {
use matrix_sdk_crypto::types::requests::OutgoingRequests::*;
use matrix_sdk_crypto::types::requests::AnyOutgoingRequest::*;

match r.request() {
KeysUpload(u) => {
Expand Down
4 changes: 2 additions & 2 deletions crates/matrix-sdk-crypto/src/gossiping/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1117,7 +1117,7 @@ mod tests {
use crate::{
gossiping::KeyForwardDecision,
olm::OutboundGroupSession,
types::requests::OutgoingRequests,
types::requests::AnyOutgoingRequest,
types::{
events::{
forwarded_room_key::ForwardedRoomKeyContent, olm_v1::AnyDecryptedOlmEvent,
Expand Down Expand Up @@ -2066,7 +2066,7 @@ mod tests {
assert_eq!(bob_machine.outgoing_to_device_requests().await.unwrap().len(), 1);
assert_matches!(
bob_machine.outgoing_to_device_requests().await.unwrap()[0].request(),
OutgoingRequests::KeysClaim(_)
AnyOutgoingRequest::KeysClaim(_)
);
assert!(!bob_machine.inner.users_for_key_claim.read().unwrap().is_empty());
assert!(!bob_machine.inner.wait_queue.is_empty());
Expand Down
4 changes: 2 additions & 2 deletions crates/matrix-sdk-crypto/src/machine/test_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use serde_json::json;

use crate::{
store::Changes,
types::{events::ToDeviceEvent, requests::OutgoingRequests},
types::{events::ToDeviceEvent, requests::AnyOutgoingRequest},
CrossSigningBootstrapRequests, DeviceData, OlmMachine,
};

Expand Down Expand Up @@ -215,7 +215,7 @@ pub fn bootstrap_requests_to_keys_query_response(
// And if we have a device, add that
if let Some(dk) = bootstrap_requests
.upload_keys_req
.and_then(|req| as_variant!(req.request.as_ref(), OutgoingRequests::KeysUpload).cloned())
.and_then(|req| as_variant!(req.request.as_ref(), AnyOutgoingRequest::KeysUpload).cloned())
.and_then(|keys_upload_request| keys_upload_request.device_keys)
{
let user_id: String = dk.get_field("user_id").unwrap().unwrap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ use crate::{
room::encrypted::{EncryptedEvent, RoomEventEncryptionScheme},
ToDeviceEvent,
},
requests::OutgoingRequests,
requests::AnyOutgoingRequest,
CrossSigningKey, DeviceKeys, EventEncryptionAlgorithm, MasterPubkey, SelfSigningPubkey,
},
utilities::json_convert,
Expand Down Expand Up @@ -498,7 +498,7 @@ async fn set_up_alice_cross_signing(alice: &OlmMachine, bob: &OlmMachine) {
upload_signing_keys_req.self_signing_key.unwrap().try_into().unwrap();
let upload_keys_req = cross_signing_requests.upload_keys_req.unwrap().clone();
assert_let!(
OutgoingRequests::KeysUpload(device_upload_request) = upload_keys_req.request.as_ref()
AnyOutgoingRequest::KeysUpload(device_upload_request) = upload_keys_req.request.as_ref()
);
bob.store()
.save_device_data(&[DeviceData::try_from(
Expand Down
6 changes: 3 additions & 3 deletions crates/matrix-sdk-crypto/src/machine/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ use crate::{
},
ToDeviceEvent,
},
requests::{OutgoingRequests, ToDeviceRequest},
requests::{AnyOutgoingRequest, ToDeviceRequest},
DeviceKeys, SignedKey, SigningKeys,
},
utilities::json_convert,
Expand Down Expand Up @@ -449,7 +449,7 @@ async fn test_request_missing_secrets() {
.unwrap()
.into_iter()
.filter(|outgoing| match outgoing.request.as_ref() {
OutgoingRequests::ToDeviceRequest(request) => {
AnyOutgoingRequest::ToDeviceRequest(request) => {
request.event_type.to_string() == "m.secret.request"
}
_ => false,
Expand Down Expand Up @@ -480,7 +480,7 @@ async fn test_request_missing_secrets_cross_signed() {
.unwrap()
.into_iter()
.filter(|outgoing| match outgoing.request.as_ref() {
OutgoingRequests::ToDeviceRequest(request) => {
AnyOutgoingRequest::ToDeviceRequest(request) => {
request.event_type.to_string() == "m.secret.request"
}
_ => false,
Expand Down
22 changes: 11 additions & 11 deletions crates/matrix-sdk-crypto/src/types/requests/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ use super::{

/// Enum over the different outgoing requests we can have.
#[derive(Debug)]
pub enum OutgoingRequests {
pub enum AnyOutgoingRequest {
/// The `/keys/upload` request, uploading device and one-time keys.
KeysUpload(KeysUploadRequest),
/// The `/keys/query` request, fetching the device and cross signing keys of
Expand All @@ -62,45 +62,45 @@ pub enum OutgoingRequests {
}

#[cfg(test)]
impl OutgoingRequests {
impl AnyOutgoingRequest {
/// Test helper to destructure the [`OutgoingRequests`] as a
/// [`ToDeviceRequest`].
pub fn to_device(&self) -> Option<&ToDeviceRequest> {
as_variant::as_variant!(self, Self::ToDeviceRequest)
}
}

impl From<KeysQueryRequest> for OutgoingRequests {
impl From<KeysQueryRequest> for AnyOutgoingRequest {
fn from(request: KeysQueryRequest) -> Self {
Self::KeysQuery(request)
}
}

impl From<KeysClaimRequest> for OutgoingRequests {
impl From<KeysClaimRequest> for AnyOutgoingRequest {
fn from(r: KeysClaimRequest) -> Self {
Self::KeysClaim(r)
}
}

impl From<KeysUploadRequest> for OutgoingRequests {
impl From<KeysUploadRequest> for AnyOutgoingRequest {
fn from(request: KeysUploadRequest) -> Self {
Self::KeysUpload(request)
}
}

impl From<ToDeviceRequest> for OutgoingRequests {
impl From<ToDeviceRequest> for AnyOutgoingRequest {
fn from(request: ToDeviceRequest) -> Self {
Self::ToDeviceRequest(request)
}
}

impl From<RoomMessageRequest> for OutgoingRequests {
impl From<RoomMessageRequest> for AnyOutgoingRequest {
fn from(request: RoomMessageRequest) -> Self {
Self::RoomMessage(request)
}
}

impl From<SignatureUploadRequest> for OutgoingRequests {
impl From<SignatureUploadRequest> for AnyOutgoingRequest {
fn from(request: SignatureUploadRequest) -> Self {
Self::SignatureUpload(request)
}
Expand All @@ -124,11 +124,11 @@ impl From<KeysUploadRequest> for OutgoingRequest {
}
}

impl From<OutgoingVerificationRequest> for OutgoingRequests {
impl From<OutgoingVerificationRequest> for AnyOutgoingRequest {
fn from(request: OutgoingVerificationRequest) -> Self {
match request {
OutgoingVerificationRequest::ToDevice(r) => OutgoingRequests::ToDeviceRequest(r),
OutgoingVerificationRequest::InRoom(r) => OutgoingRequests::RoomMessage(r),
OutgoingVerificationRequest::ToDevice(r) => AnyOutgoingRequest::ToDeviceRequest(r),
OutgoingVerificationRequest::InRoom(r) => AnyOutgoingRequest::RoomMessage(r),
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/matrix-sdk-crypto/src/types/requests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub struct OutgoingRequest {
/// response.
pub(crate) request_id: OwnedTransactionId,
/// The underlying outgoing request.
pub(crate) request: Arc<OutgoingRequests>,
pub(crate) request: Arc<AnyOutgoingRequest>,
}

impl OutgoingRequest {
Expand All @@ -52,7 +52,7 @@ impl OutgoingRequest {
}

/// Get the underlying outgoing request.
pub fn request(&self) -> &OutgoingRequests {
pub fn request(&self) -> &AnyOutgoingRequest {
&self.request
}
}
14 changes: 7 additions & 7 deletions crates/matrix-sdk-crypto/src/verification/event_enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -765,15 +765,15 @@ impl TryFrom<OutgoingRequest> for OutgoingContent {
type Error = String;

fn try_from(value: OutgoingRequest) -> Result<Self, Self::Error> {
use crate::types::requests::OutgoingRequests;
use crate::types::requests::AnyOutgoingRequest;

match value.request() {
OutgoingRequests::KeysUpload(_)
| OutgoingRequests::KeysQuery(_)
| OutgoingRequests::SignatureUpload(_)
| OutgoingRequests::KeysClaim(_) => Err("Invalid request type".to_owned()),
OutgoingRequests::ToDeviceRequest(r) => Self::try_from(r.clone()),
OutgoingRequests::RoomMessage(r) => Ok(Self::from(r.clone())),
AnyOutgoingRequest::KeysUpload(_)
| AnyOutgoingRequest::KeysQuery(_)
| AnyOutgoingRequest::SignatureUpload(_)
| AnyOutgoingRequest::KeysClaim(_) => Err("Invalid request type".to_owned()),
AnyOutgoingRequest::ToDeviceRequest(r) => Self::try_from(r.clone()),
AnyOutgoingRequest::RoomMessage(r) => Ok(Self::from(r.clone())),
}
}
}
4 changes: 2 additions & 2 deletions 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, OutgoingRequests, OutgoingVerificationRequest},
requests::{OutgoingRequest, AnyOutgoingRequest, OutgoingVerificationRequest},
},
Account, DeviceData, OtherUserIdentityData, OwnUserIdentityData,
};
Expand All @@ -767,7 +767,7 @@ pub(crate) mod tests {
request: &OutgoingRequest,
) -> ToDeviceEvents {
match request.request() {
OutgoingRequests::ToDeviceRequest(r) => request_to_event(sender, &r.clone().into()),
AnyOutgoingRequest::ToDeviceRequest(r) => request_to_event(sender, &r.clone().into()),
_ => panic!("Unsupported outgoing request"),
}
}
Expand Down
14 changes: 7 additions & 7 deletions crates/matrix-sdk/src/encryption/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -613,28 +613,28 @@ impl Client {
}

async fn send_outgoing_request(&self, r: OutgoingRequest) -> Result<()> {
use matrix_sdk_base::crypto::types::requests::OutgoingRequests;
use matrix_sdk_base::crypto::types::requests::AnyOutgoingRequest;

match r.request() {
OutgoingRequests::KeysQuery(request) => {
AnyOutgoingRequest::KeysQuery(request) => {
self.keys_query(r.request_id(), request.device_keys.clone()).await?;
}
OutgoingRequests::KeysUpload(request) => {
AnyOutgoingRequest::KeysUpload(request) => {
self.keys_upload(r.request_id(), request).await?;
}
OutgoingRequests::ToDeviceRequest(request) => {
AnyOutgoingRequest::ToDeviceRequest(request) => {
let response = self.send_to_device(request).await?;
self.mark_request_as_sent(r.request_id(), &response).await?;
}
OutgoingRequests::SignatureUpload(request) => {
AnyOutgoingRequest::SignatureUpload(request) => {
let response = self.send(request.clone(), None).await?;
self.mark_request_as_sent(r.request_id(), &response).await?;
}
OutgoingRequests::RoomMessage(request) => {
AnyOutgoingRequest::RoomMessage(request) => {
let response = self.room_send_helper(request).await?;
self.mark_request_as_sent(r.request_id(), &response).await?;
}
OutgoingRequests::KeysClaim(request) => {
AnyOutgoingRequest::KeysClaim(request) => {
let response = self.send(request.clone(), None).await?;
self.mark_request_as_sent(r.request_id(), &response).await?;
}
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, OutgoingRequests};
use matrix_sdk_base::crypto::types::requests::{IncomingResponse, AnyOutgoingRequest};
use matrix_sdk_test::ruma_response_from_json;
use ruma::user_id;

Expand All @@ -1716,8 +1716,8 @@ mod tests {
let outgoing_requests = olm_machine.outgoing_requests().await?;

assert_eq!(outgoing_requests.len(), 2);
assert_matches!(outgoing_requests[0].request(), OutgoingRequests::KeysUpload(_));
assert_matches!(outgoing_requests[1].request(), OutgoingRequests::KeysQuery(_));
assert_matches!(outgoing_requests[0].request(), AnyOutgoingRequest::KeysUpload(_));
assert_matches!(outgoing_requests[1].request(), AnyOutgoingRequest::KeysQuery(_));

// Fake responses.
olm_machine
Expand Down Expand Up @@ -1745,7 +1745,7 @@ mod tests {
let outgoing_requests = olm_machine.outgoing_requests().await?;

assert_eq!(outgoing_requests.len(), 1);
assert_matches!(outgoing_requests[0].request(), OutgoingRequests::KeysQuery(_));
assert_matches!(outgoing_requests[0].request(), AnyOutgoingRequest::KeysQuery(_));

olm_machine
.mark_request_as_sent(
Expand Down Expand Up @@ -1788,7 +1788,7 @@ mod tests {
assert_eq!(outgoing_requests.len(), 1);
assert_matches!(
outgoing_requests[0].request(),
OutgoingRequests::KeysQuery(request) => {
AnyOutgoingRequest::KeysQuery(request) => {
assert!(request.device_keys.contains_key(alice));
assert!(request.device_keys.contains_key(bob));
assert!(request.device_keys.contains_key(me));
Expand Down

0 comments on commit 600a708

Please sign in to comment.