From e8c5b0766e8481eec676a26ecc661939813f5b4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Tue, 14 Sep 2021 12:31:40 +0200 Subject: [PATCH] chore(sdk): Move all the crypto related module under an encryption module --- .../matrix_sdk/examples/emoji_verification.rs | 2 +- crates/matrix_sdk/src/client.rs | 12 +++++++----- .../{ => encryption}/identities/devices.rs | 2 +- .../src/{ => encryption}/identities/mod.rs | 0 .../src/{ => encryption}/identities/users.rs | 2 +- crates/matrix_sdk/src/encryption/mod.rs | 19 +++++++++++++++++++ .../src/{ => encryption}/verification/mod.rs | 0 .../{ => encryption}/verification/qrcode.rs | 0 .../{ => encryption}/verification/requests.rs | 0 .../src/{ => encryption}/verification/sas.rs | 0 crates/matrix_sdk/src/lib.rs | 8 +------- 11 files changed, 30 insertions(+), 15 deletions(-) rename crates/matrix_sdk/src/{ => encryption}/identities/devices.rs (99%) rename crates/matrix_sdk/src/{ => encryption}/identities/mod.rs (100%) rename crates/matrix_sdk/src/{ => encryption}/identities/users.rs (99%) create mode 100644 crates/matrix_sdk/src/encryption/mod.rs rename crates/matrix_sdk/src/{ => encryption}/verification/mod.rs (100%) rename crates/matrix_sdk/src/{ => encryption}/verification/qrcode.rs (100%) rename crates/matrix_sdk/src/{ => encryption}/verification/requests.rs (100%) rename crates/matrix_sdk/src/{ => encryption}/verification/sas.rs (100%) diff --git a/crates/matrix_sdk/examples/emoji_verification.rs b/crates/matrix_sdk/examples/emoji_verification.rs index 1307d9a2..f163b6dd 100644 --- a/crates/matrix_sdk/examples/emoji_verification.rs +++ b/crates/matrix_sdk/examples/emoji_verification.rs @@ -9,13 +9,13 @@ use std::{ use matrix_sdk::{ self, + encryption::verification::{SasVerification, Verification}, ruma::{ events::{ room::message::MessageType, AnySyncMessageEvent, AnySyncRoomEvent, AnyToDeviceEvent, }, UserId, }, - verification::{SasVerification, Verification}, Client, LoopCtrl, SyncSettings, }; use url::Url; diff --git a/crates/matrix_sdk/src/client.rs b/crates/matrix_sdk/src/client.rs index 6bffe85e..e75435c4 100644 --- a/crates/matrix_sdk/src/client.rs +++ b/crates/matrix_sdk/src/client.rs @@ -139,12 +139,14 @@ use ruma::{ }; #[cfg(all(feature = "qrcode", feature = "encryption"))] -use crate::verification::QrVerification; +use crate::encryption::verification::QrVerification; #[cfg(feature = "encryption")] use crate::{ + encryption::{ + identities::{Device, UserDevices}, + verification::{SasVerification, Verification, VerificationRequest}, + }, error::RoomKeyImportError, - identities::{Device, UserDevices}, - verification::{SasVerification, Verification, VerificationRequest}, }; use crate::{ error::{HttpError, HttpResult}, @@ -2685,8 +2687,8 @@ impl Client { pub async fn get_user_identity( &self, user_id: &UserId, - ) -> StdResult, CryptoStoreError> { - use crate::identities::UserIdentity; + ) -> StdResult, CryptoStoreError> { + use crate::encryption::identities::UserIdentity; if let Some(olm) = self.base_client.olm_machine().await { let identity = olm.get_identity(user_id).await?; diff --git a/crates/matrix_sdk/src/identities/devices.rs b/crates/matrix_sdk/src/encryption/identities/devices.rs similarity index 99% rename from crates/matrix_sdk/src/identities/devices.rs rename to crates/matrix_sdk/src/encryption/identities/devices.rs index 1580d5e8..eb615620 100644 --- a/crates/matrix_sdk/src/identities/devices.rs +++ b/crates/matrix_sdk/src/encryption/identities/devices.rs @@ -22,8 +22,8 @@ use ruma::{events::key::verification::VerificationMethod, DeviceId, DeviceIdBox} use super::ManualVerifyError; use crate::{ + encryption::verification::{SasVerification, VerificationRequest}, error::Result, - verification::{SasVerification, VerificationRequest}, Client, }; diff --git a/crates/matrix_sdk/src/identities/mod.rs b/crates/matrix_sdk/src/encryption/identities/mod.rs similarity index 100% rename from crates/matrix_sdk/src/identities/mod.rs rename to crates/matrix_sdk/src/encryption/identities/mod.rs diff --git a/crates/matrix_sdk/src/identities/users.rs b/crates/matrix_sdk/src/encryption/identities/users.rs similarity index 99% rename from crates/matrix_sdk/src/identities/users.rs rename to crates/matrix_sdk/src/encryption/identities/users.rs index 871eee73..38b86200 100644 --- a/crates/matrix_sdk/src/identities/users.rs +++ b/crates/matrix_sdk/src/encryption/identities/users.rs @@ -30,7 +30,7 @@ use ruma::{ }; use super::{ManualVerifyError, RequestVerificationError}; -use crate::{room::Joined, verification::VerificationRequest, Client}; +use crate::{encryption::verification::VerificationRequest, room::Joined, Client}; /// A struct representing a E2EE capable identity of a user. /// diff --git a/crates/matrix_sdk/src/encryption/mod.rs b/crates/matrix_sdk/src/encryption/mod.rs new file mode 100644 index 00000000..9374d8b6 --- /dev/null +++ b/crates/matrix_sdk/src/encryption/mod.rs @@ -0,0 +1,19 @@ +// Copyright 2021 The Matrix.org Foundation C.I.C. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//! End to end encryption related types + +pub mod identities; +pub mod verification; +pub use matrix_sdk_base::crypto::{EncryptionInfo, LocalTrust}; diff --git a/crates/matrix_sdk/src/verification/mod.rs b/crates/matrix_sdk/src/encryption/verification/mod.rs similarity index 100% rename from crates/matrix_sdk/src/verification/mod.rs rename to crates/matrix_sdk/src/encryption/verification/mod.rs diff --git a/crates/matrix_sdk/src/verification/qrcode.rs b/crates/matrix_sdk/src/encryption/verification/qrcode.rs similarity index 100% rename from crates/matrix_sdk/src/verification/qrcode.rs rename to crates/matrix_sdk/src/encryption/verification/qrcode.rs diff --git a/crates/matrix_sdk/src/verification/requests.rs b/crates/matrix_sdk/src/encryption/verification/requests.rs similarity index 100% rename from crates/matrix_sdk/src/verification/requests.rs rename to crates/matrix_sdk/src/encryption/verification/requests.rs diff --git a/crates/matrix_sdk/src/verification/sas.rs b/crates/matrix_sdk/src/encryption/verification/sas.rs similarity index 100% rename from crates/matrix_sdk/src/verification/sas.rs rename to crates/matrix_sdk/src/encryption/verification/sas.rs diff --git a/crates/matrix_sdk/src/lib.rs b/crates/matrix_sdk/src/lib.rs index 1cfcec8e..87972ea2 100644 --- a/crates/matrix_sdk/src/lib.rs +++ b/crates/matrix_sdk/src/lib.rs @@ -37,9 +37,6 @@ compile_error!("only one of 'native-tls' or 'rustls-tls' features can be enabled compile_error!("'sso_login' cannot be enabled on 'wasm32' arch"); pub use bytes; -#[cfg(feature = "encryption")] -#[cfg_attr(feature = "docs", doc(cfg(encryption)))] -pub use matrix_sdk_base::crypto::{EncryptionInfo, LocalTrust}; pub use matrix_sdk_base::{ media, Room as BaseRoom, RoomInfo, RoomMember as BaseRoomMember, RoomType, Session, StateChanges, StoreError, @@ -60,10 +57,7 @@ mod room_member; #[cfg(feature = "encryption")] #[cfg_attr(feature = "docs", doc(cfg(encryption)))] -pub mod identities; -#[cfg(feature = "encryption")] -#[cfg_attr(feature = "docs", doc(cfg(encryption)))] -pub mod verification; +pub mod encryption; pub use client::{Client, ClientConfig, LoopCtrl, RequestConfig, SyncSettings}; pub use error::{Error, HttpError, HttpResult, Result};