Skip to content

Commit 84c6572

Browse files
committed
refactor: Batch of unrelated changes
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
1 parent c7940ed commit 84c6572

File tree

11 files changed

+27
-29
lines changed

11 files changed

+27
-29
lines changed

bindings/matrix-sdk-ffi/src/client.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2402,9 +2402,7 @@ impl TryFrom<AllowRule> for RumaAllowRule {
24022402
match value {
24032403
AllowRule::RoomMembership { room_id } => {
24042404
let room_id = RoomId::parse(room_id)?;
2405-
Ok(Self::RoomMembership(ruma::events::room::join_rules::RoomMembership::new(
2406-
room_id,
2407-
)))
2405+
Ok(Self::RoomMembership(ruma::room::RoomMembership::new(room_id)))
24082406
}
24092407
AllowRule::Custom { json } => Ok(Self::_Custom(Box::new(serde_json::from_str(&json)?))),
24102408
}

bindings/matrix-sdk-ffi/src/room/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ impl Room {
484484
/// # Errors
485485
///
486486
/// Returns an error if the room is not found or on rate limit
487-
pub async fn report_room(&self, reason: Option<String>) -> Result<(), ClientError> {
487+
pub async fn report_room(&self, reason: String) -> Result<(), ClientError> {
488488
self.inner.report_room(reason).await?;
489489

490490
Ok(())

crates/matrix-sdk-crypto/src/file_encryption/attachments.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,20 +136,19 @@ impl<'a, R: Read + 'a> AttachmentDecryptor<'a, R> {
136136

137137
let hash =
138138
info.hashes.get("sha256").ok_or(DecryptorError::MissingHash)?.as_bytes().to_owned();
139-
let mut key = info.key.k.into_inner();
139+
let key = info.key.k.as_bytes();
140140
let iv = info.iv.into_inner();
141141

142142
if key.len() != KEY_SIZE {
143143
return Err(DecryptorError::KeyNonceLength);
144144
}
145145

146-
let key_array = GenericArray::from_slice(&key);
146+
let key_array = GenericArray::from_slice(key);
147147
let iv = GenericArray::from_exact_iter(iv).ok_or(DecryptorError::KeyNonceLength)?;
148148

149149
let sha = Sha256::default();
150150

151151
let aes = Aes256Ctr::new(key_array, &iv);
152-
key.zeroize();
153152

154153
Ok(AttachmentDecryptor { inner: input, expected_hash: hash, sha, aes })
155154
}

crates/matrix-sdk-crypto/src/machine/test_helpers.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ pub fn bootstrap_requests_to_keys_query_response(
334334
/// Helper for [`create_signed_device_of_unverified_user`] and
335335
/// [`create_unsigned_device`].
336336
fn dummy_verification_machine() -> VerificationMachine {
337-
let account = Account::new(user_id!("@TEST_USER:example.com"));
337+
let account = Account::new(user_id!("@test_user:example.com"));
338338
VerificationMachine::new(
339339
account.deref().clone(),
340340
Arc::new(Mutex::new(PrivateCrossSigningIdentity::new(account.user_id().to_owned()))),

crates/matrix-sdk-crypto/src/machine/tests/mod.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ use ruma::{
3636
room::message::{
3737
AddMentions, MessageType, Relation, ReplyWithinThread, RoomMessageEventContent,
3838
},
39-
AnyMessageLikeEvent, AnyMessageLikeEventContent, AnyToDeviceEvent, MessageLikeEvent,
40-
OriginalMessageLikeEvent, ToDeviceEventType,
39+
AnyMessageLikeEvent, AnyMessageLikeEventContent, AnySyncMessageLikeEvent, AnyToDeviceEvent,
40+
MessageLikeEvent, OriginalMessageLikeEvent, ToDeviceEventType,
4141
},
4242
room_id,
4343
serde::Raw,
@@ -1442,8 +1442,8 @@ async fn test_unsigned_decryption() {
14421442

14431443
// Encrypt a second message, an edit.
14441444
let second_message_text = "This is the ~~original~~ edited message";
1445-
let second_message_content = RoomMessageEventContent::text_plain(second_message_text)
1446-
.make_replacement(first_message, None);
1445+
let second_message_content =
1446+
RoomMessageEventContent::text_plain(second_message_text).make_replacement(first_message);
14471447
let second_message_encrypted_content =
14481448
alice.encrypt_room_event(room_id, second_message_content).await.unwrap();
14491449

@@ -1579,7 +1579,10 @@ async fn test_unsigned_decryption() {
15791579
assert!(first_message.unsigned.relations.replace.is_some());
15801580
// Deserialization of the thread event succeeded, but it is still encrypted.
15811581
let thread = first_message.unsigned.relations.thread.as_ref().unwrap();
1582-
assert_matches!(thread.latest_event.deserialize(), Ok(AnyMessageLikeEvent::RoomEncrypted(_)));
1582+
assert_matches!(
1583+
thread.latest_event.deserialize(),
1584+
Ok(AnySyncMessageLikeEvent::RoomEncrypted(_))
1585+
);
15831586

15841587
let unsigned_encryption_info = raw_decrypted_event.unsigned_encryption_info.unwrap();
15851588
assert_eq!(unsigned_encryption_info.len(), 2);
@@ -1625,7 +1628,7 @@ async fn test_unsigned_decryption() {
16251628
let thread = &first_message.unsigned.relations.thread.as_ref().unwrap();
16261629
assert_matches!(
16271630
thread.latest_event.deserialize(),
1628-
Ok(AnyMessageLikeEvent::RoomMessage(third_message))
1631+
Ok(AnySyncMessageLikeEvent::RoomMessage(third_message))
16291632
);
16301633
let third_message = third_message.as_original().unwrap();
16311634
assert_eq!(third_message.content.body(), third_message_text);

crates/matrix-sdk/src/client/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,8 @@ use ruma::{
4848
device::{delete_devices, get_devices, update_device},
4949
directory::{get_public_rooms, get_public_rooms_filtered},
5050
discovery::{
51-
discover_homeserver,
52-
discover_homeserver::RtcFocusInfo,
53-
get_capabilities::{self, Capabilities},
51+
discover_homeserver::{self, RtcFocusInfo},
52+
get_capabilities::{self, v3::Capabilities},
5453
get_supported_versions,
5554
},
5655
error::ErrorKind,

crates/matrix-sdk/src/encryption/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,8 +348,9 @@ pub struct OAuthCrossSigningResetInfo {
348348

349349
impl OAuthCrossSigningResetInfo {
350350
fn from_auth_info(auth_info: &UiaaInfo) -> Result<Self> {
351-
let parameters =
352-
serde_json::from_str::<OAuthCrossSigningResetUiaaParameters>(auth_info.params.get())?;
351+
let parameters = serde_json::from_str::<OAuthCrossSigningResetUiaaParameters>(
352+
auth_info.params.as_ref().map(|value| value.get()).unwrap_or_default(),
353+
)?;
353354

354355
Ok(OAuthCrossSigningResetInfo { approval_url: parameters.reset.url })
355356
}

crates/matrix-sdk/src/event_handler/static_events.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,9 @@
1616

1717
use ruma::{
1818
events::{
19-
self,
20-
presence::{PresenceEvent, PresenceEventContent},
21-
AnyGlobalAccountDataEvent, AnyRoomAccountDataEvent, AnyStrippedStateEvent,
22-
AnySyncEphemeralRoomEvent, AnySyncMessageLikeEvent, AnySyncStateEvent,
23-
AnySyncTimelineEvent, AnyToDeviceEvent, EphemeralRoomEventContent,
19+
self, presence::PresenceEvent, AnyGlobalAccountDataEvent, AnyRoomAccountDataEvent,
20+
AnyStrippedStateEvent, AnySyncEphemeralRoomEvent, AnySyncMessageLikeEvent,
21+
AnySyncStateEvent, AnySyncTimelineEvent, AnyToDeviceEvent, EphemeralRoomEventContent,
2422
GlobalAccountDataEventContent, MessageLikeEventContent, PossiblyRedactedStateEventContent,
2523
RedactContent, RedactedMessageLikeEventContent, RedactedStateEventContent,
2624
RoomAccountDataEventContent, StaticEventContent, StaticStateEventContent,
@@ -141,7 +139,7 @@ where
141139

142140
impl SyncEvent for PresenceEvent {
143141
const KIND: HandlerKind = HandlerKind::Presence;
144-
const TYPE: Option<&'static str> = Some(PresenceEventContent::TYPE);
142+
const TYPE: Option<&'static str> = None;
145143
}
146144

147145
impl SyncEvent for AnyGlobalAccountDataEvent {

crates/matrix-sdk/src/http_client/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ impl HttpClient {
171171
AuthScheme::AccessToken
172172
| AuthScheme::AccessTokenOptional
173173
| AuthScheme::AppserviceToken
174+
| AuthScheme::AppserviceTokenOptional
174175
| AuthScheme::None => {}
175176
AuthScheme::ServerSignatures => {
176177
return Err(HttpError::NotClientRequest);

crates/matrix-sdk/src/room/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3159,9 +3159,8 @@ impl Room {
31593159
/// # Errors
31603160
///
31613161
/// Returns an error if the room is not found or on rate limit
3162-
pub async fn report_room(&self, reason: Option<String>) -> Result<report_room::v3::Response> {
3163-
let mut request = report_room::v3::Request::new(self.inner.room_id().to_owned());
3164-
request.reason = reason;
3162+
pub async fn report_room(&self, reason: String) -> Result<report_room::v3::Response> {
3163+
let request = report_room::v3::Request::new(self.inner.room_id().to_owned(), reason);
31653164

31663165
Ok(self.client.send(request).await?)
31673166
}

0 commit comments

Comments
 (0)