Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade Ruma #471

Merged
merged 14 commits into from
Feb 1, 2022
6 changes: 5 additions & 1 deletion crates/matrix-qrcode/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,8 @@ thiserror = "1.0.25"

[dependencies.ruma-identifiers]
git = "https://github.com/ruma/ruma/"
rev = "fdbc4d6d1dd273c8a6ac95b329943ed8c68df70d"
rev = "37095f88553b311e7a70adaaabe39976fb8ff71c"

[dependencies.ruma-serde]
git = "https://github.com/ruma/ruma/"
rev = "37095f88553b311e7a70adaaabe39976fb8ff71c"
17 changes: 9 additions & 8 deletions crates/matrix-qrcode/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use byteorder::{BigEndian, ReadBytesExt};
use image::{DynamicImage, GenericImage, GenericImageView, ImageBuffer, Luma};
use qrcode::QrCode;
use ruma_identifiers::EventId;
use ruma_serde::Base64;

#[cfg(feature = "decode_image")]
use crate::utils::decode_qr;
Expand Down Expand Up @@ -312,7 +313,7 @@ impl QrVerificationData {
let first_key = base_64_encode(&first_key);
let second_key = base_64_encode(&second_key);
let flow_id = String::from_utf8(flow_id)?;
let shared_secret = base_64_encode(&shared_secret);
let shared_secret = Base64::new(shared_secret);

match mode {
VerificationData::QR_MODE => {
Expand Down Expand Up @@ -360,7 +361,7 @@ impl QrVerificationData {
}

/// Get the secret of this `QrVerificationData`.
pub fn secret(&self) -> &str {
pub fn secret(&self) -> &Base64 {
match self {
QrVerificationData::Verification(v) => &v.shared_secret,
QrVerificationData::SelfVerification(v) => &v.shared_secret,
Expand All @@ -378,7 +379,7 @@ pub struct VerificationData {
event_id: Box<EventId>,
first_master_key: String,
second_master_key: String,
shared_secret: String,
shared_secret: Base64,
}

impl VerificationData {
Expand All @@ -401,7 +402,7 @@ impl VerificationData {
event_id: Box<EventId>,
first_key: String,
second_key: String,
shared_secret: String,
shared_secret: Base64,
) -> Self {
Self { event_id, first_master_key: first_key, second_master_key: second_key, shared_secret }
}
Expand Down Expand Up @@ -477,7 +478,7 @@ pub struct SelfVerificationData {
transaction_id: String,
master_key: String,
device_key: String,
shared_secret: String,
shared_secret: Base64,
}

impl SelfVerificationData {
Expand All @@ -504,7 +505,7 @@ impl SelfVerificationData {
transaction_id: String,
master_key: String,
device_key: String,
shared_secret: String,
shared_secret: Base64,
) -> Self {
Self { transaction_id, master_key, device_key, shared_secret }
}
Expand Down Expand Up @@ -580,7 +581,7 @@ pub struct SelfVerificationNoMasterKey {
transaction_id: String,
device_key: String,
master_key: String,
shared_secret: String,
shared_secret: Base64,
}

impl SelfVerificationNoMasterKey {
Expand All @@ -607,7 +608,7 @@ impl SelfVerificationNoMasterKey {
transaction_id: String,
device_key: String,
master_key: String,
shared_secret: String,
shared_secret: Base64,
) -> Self {
Self { transaction_id, device_key, master_key, shared_secret }
}
Expand Down
8 changes: 4 additions & 4 deletions crates/matrix-qrcode/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use base64::{decode_config, encode_config, STANDARD_NO_PAD};
#[cfg(feature = "decode_image")]
use image::{GenericImage, GenericImageView, Luma};
use qrcode::{bits::Bits, EcLevel, QrCode, Version};
use ruma_serde::Base64;

#[cfg(feature = "decode_image")]
use crate::error::DecodingError;
Expand All @@ -41,14 +42,13 @@ pub(crate) fn to_bytes(
flow_id: &str,
first_key: &str,
second_key: &str,
shared_secret: &str,
shared_secret: &Base64,
) -> Result<Vec<u8>, EncodingError> {
let flow_id_len: u16 = flow_id.len().try_into()?;
let flow_id_len = flow_id_len.to_be_bytes();

let first_key = base64_decode(first_key)?;
let second_key = base64_decode(second_key)?;
let shared_secret = base64_decode(shared_secret)?;

let data = [
HEADER,
Expand All @@ -58,7 +58,7 @@ pub(crate) fn to_bytes(
flow_id.as_bytes(),
&first_key,
&second_key,
&shared_secret,
shared_secret.as_bytes(),
]
.concat();

Expand All @@ -70,7 +70,7 @@ pub(crate) fn to_qr_code(
flow_id: &str,
first_key: &str,
second_key: &str,
shared_secret: &str,
shared_secret: &Base64,
) -> Result<QrCode, EncodingError> {
let data = to_bytes(mode, flow_id, first_key, second_key, shared_secret)?;

Expand Down
2 changes: 1 addition & 1 deletion crates/matrix-sdk-appservice/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ warp = { version = "0.3.1", optional = true, default-features = false }

[dependencies.ruma]
git = "https://github.com/ruma/ruma/"
rev = "fdbc4d6d1dd273c8a6ac95b329943ed8c68df70d"
rev = "37095f88553b311e7a70adaaabe39976fb8ff71c"
features = ["client-api-c", "appservice-api-s", "unstable-pre-spec"]

[dev-dependencies]
Expand Down
9 changes: 2 additions & 7 deletions crates/matrix-sdk-appservice/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,8 @@ async fn appservice(registration: Option<Registration>) -> Result<AppService> {
let client_config =
ClientConfig::default().request_config(RequestConfig::default().disable_retry());

Ok(AppService::new_with_config(
homeserver_url.as_ref(),
server_name,
registration,
client_config,
)
.await?)
AppService::new_with_config(homeserver_url.as_ref(), server_name, registration, client_config)
.await
}

#[async_test]
Expand Down
2 changes: 1 addition & 1 deletion crates/matrix-sdk-base/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ zeroize = { version = "1.3.0", features = ["zeroize_derive"] }

[dependencies.ruma]
git = "https://github.com/ruma/ruma/"
rev = "fdbc4d6d1dd273c8a6ac95b329943ed8c68df70d"
rev = "37095f88553b311e7a70adaaabe39976fb8ff71c"
features = ["client-api-c", "unstable-pre-spec"]

[target.'cfg(not(target_arch = "wasm32"))'.dependencies.tokio]
Expand Down
16 changes: 8 additions & 8 deletions crates/matrix-sdk-base/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ use std::{
sync::Arc,
};

#[cfg(feature = "encryption")]
use matrix_sdk_common::locks::Mutex;
use matrix_sdk_common::{
deserialized_responses::{
AmbiguityChanges, JoinedRoom, LeftRoom, MemberEvent, MembersResponse, Rooms,
Expand All @@ -33,8 +35,6 @@ use matrix_sdk_common::{
locks::RwLock,
};
#[cfg(feature = "encryption")]
use matrix_sdk_common::{locks::Mutex, uuid::Uuid};
#[cfg(feature = "encryption")]
use matrix_sdk_crypto::{
store::{CryptoStore, CryptoStoreError},
Device, EncryptionSettings, IncomingResponse, MegolmError, OlmError, OlmMachine,
Expand All @@ -47,7 +47,7 @@ use ruma::{
room::{encrypted::RoomEncryptedEventContent, history_visibility::HistoryVisibility},
AnySyncMessageEvent, MessageEventContent,
},
DeviceId,
DeviceId, TransactionId,
};
use ruma::{
api::client::r0::{self as api, push::get_notifications::Notification},
Expand Down Expand Up @@ -583,9 +583,9 @@ impl BaseClient {
}
}

changes.members.insert((&*room_id).to_owned(), members);
changes.profiles.insert((&*room_id).to_owned(), profiles);
changes.state.insert((&*room_id).to_owned(), state_events);
changes.members.insert((*room_id).to_owned(), members);
changes.profiles.insert((*room_id).to_owned(), profiles);
changes.state.insert((*room_id).to_owned(), state_events);

Ok(user_ids)
}
Expand Down Expand Up @@ -1038,7 +1038,7 @@ impl BaseClient {
#[cfg(feature = "encryption")]
pub async fn mark_request_as_sent<'a>(
&self,
request_id: &Uuid,
request_id: &TransactionId,
response: impl Into<IncomingResponse<'a>>,
) -> Result<()> {
let olm = self.olm.lock().await;
Expand All @@ -1056,7 +1056,7 @@ impl BaseClient {
pub async fn get_missing_sessions(
&self,
users: impl Iterator<Item = &UserId>,
) -> Result<Option<(Uuid, KeysClaimRequest)>> {
) -> Result<Option<(Box<TransactionId>, KeysClaimRequest)>> {
let olm = self.olm.lock().await;

match &*olm {
Expand Down
32 changes: 25 additions & 7 deletions crates/matrix-sdk-base/src/store/sled_store/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,19 +93,37 @@ trait EncodeKey {
fn encode(&self) -> Vec<u8>;
}

impl EncodeKey for &UserId {
impl<T: EncodeKey> EncodeKey for &T {
fn encode(&self) -> Vec<u8> {
T::encode(self)
}
}

impl<T: EncodeKey> EncodeKey for Box<T> {
fn encode(&self) -> Vec<u8> {
T::encode(self)
}
}

impl EncodeKey for UserId {
fn encode(&self) -> Vec<u8> {
self.as_str().encode()
}
}

impl EncodeKey for RoomId {
fn encode(&self) -> Vec<u8> {
self.as_str().encode()
}
}

impl EncodeKey for &RoomId {
impl EncodeKey for String {
fn encode(&self) -> Vec<u8> {
self.as_str().encode()
}
}

impl EncodeKey for &str {
impl EncodeKey for str {
fn encode(&self) -> Vec<u8> {
[self.as_bytes(), &[ENCODE_SEPARATOR]].concat()
}
Expand Down Expand Up @@ -425,7 +443,7 @@ impl SledStore {

for (event_type, event) in &changes.account_data {
account_data.insert(
event_type.as_str().encode(),
event_type.encode(),
self.serialize_event(&event)
.map_err(ConflictableTransactionError::Abort)?,
)?;
Expand Down Expand Up @@ -456,23 +474,23 @@ impl SledStore {

for (room_id, room_info) in &changes.room_infos {
rooms.insert(
(&**room_id).encode(),
room_id.encode(),
self.serialize_event(room_info)
.map_err(ConflictableTransactionError::Abort)?,
)?;
}

for (sender, event) in &changes.presence {
presence.insert(
(&**sender).encode(),
sender.encode(),
self.serialize_event(&event)
.map_err(ConflictableTransactionError::Abort)?,
)?;
}

for (room_id, info) in &changes.invited_room_info {
striped_rooms.insert(
(&**room_id).encode(),
room_id.encode(),
self.serialize_event(&info)
.map_err(ConflictableTransactionError::Abort)?,
)?;
Expand Down
13 changes: 1 addition & 12 deletions crates/matrix-sdk-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,9 @@ serde = "1.0.126"

[dependencies.ruma]
git = "https://github.com/ruma/ruma/"
rev = "fdbc4d6d1dd273c8a6ac95b329943ed8c68df70d"
rev = "37095f88553b311e7a70adaaabe39976fb8ff71c"
features = ["client-api-c"]

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
uuid = { version = "0.8.2", default-features = false, features = [
"v4",
"serde",
] }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies.tokio]
version = "1.7.1"
default-features = false
Expand All @@ -43,8 +37,3 @@ features = ["now"]
async-lock = "2.4.0"
futures-util = { version = "0.3.15", default-features = false, features = ["channel"] }
wasm-bindgen-futures = "0.4.24"
uuid = { version = "0.8.2", default-features = false, features = [
"v4",
"wasm-bindgen",
"serde",
] }
1 change: 0 additions & 1 deletion crates/matrix-sdk-common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

pub use async_trait::async_trait;
pub use instant;
pub use uuid;

pub mod deserialized_responses;
pub mod executor;
Expand Down
4 changes: 2 additions & 2 deletions crates/matrix-sdk-crypto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ zeroize = { version = "1.3.0", features = ["zeroize_derive"] }

[dependencies.ruma]
git = "https://github.com/ruma/ruma/"
rev = "fdbc4d6d1dd273c8a6ac95b329943ed8c68df70d"
features = ["client-api-c", "unstable-pre-spec"]
rev = "37095f88553b311e7a70adaaabe39976fb8ff71c"
features = ["client-api-c", "rand", "unstable-pre-spec"]

[dev-dependencies]
criterion = { version = "0.3.4", features = [
Expand Down
Loading