Skip to content

Commit f2ba338

Browse files
jplatteandybalaam
authored andcommitted
Fix new rustc + clippy warnings
1 parent 0035259 commit f2ba338

File tree

18 files changed

+139
-164
lines changed

18 files changed

+139
-164
lines changed

crates/matrix-sdk-crypto/src/backups/mod.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -357,14 +357,10 @@ impl BackupMachine {
357357
let private_identity = self.store.private_identity();
358358
let identity = private_identity.lock().await;
359359

360-
if let Some(key_id) = identity.master_key_id().await {
361-
if let Ok(signature) = identity.sign(&canonical_json).await {
362-
data.signatures.add_signature(
363-
self.store.user_id().to_owned(),
364-
key_id,
365-
signature,
366-
);
367-
}
360+
if let Some(key_id) = identity.master_key_id().await
361+
&& let Ok(signature) = identity.sign(&canonical_json).await
362+
{
363+
data.signatures.add_signature(self.store.user_id().to_owned(), key_id, signature);
368364
}
369365

370366
let cache = self.store.cache().await?;

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -781,14 +781,14 @@ impl GossipMachine {
781781
room_id: &RoomId,
782782
event: &EncryptedEvent,
783783
) -> Result<bool, CryptoStoreError> {
784-
if let Some(info) = event.room_key_info(room_id).map(|i| i.into()) {
785-
if self.should_request_key(&info).await? {
786-
// Size of the request_key_helper future should not impact this
787-
// async fn since it is likely enough that this branch won't be
788-
// entered.
789-
Box::pin(self.request_key_helper(info)).await?;
790-
return Ok(true);
791-
}
784+
if let Some(info) = event.room_key_info(room_id).map(|i| i.into())
785+
&& self.should_request_key(&info).await?
786+
{
787+
// Size of the request_key_helper future should not impact this
788+
// async fn since it is likely enough that this branch won't be
789+
// entered.
790+
Box::pin(self.request_key_helper(info)).await?;
791+
return Ok(true);
792792
}
793793

794794
Ok(false)

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1583,15 +1583,14 @@ impl OlmMachine {
15831583
ToDeviceUnableToDecryptReason::DecryptionFailure
15841584
};
15851585

1586-
if let OlmError::SessionWedged(sender, curve_key) = err {
1587-
if let Err(e) =
1586+
if let OlmError::SessionWedged(sender, curve_key) = err
1587+
&& let Err(e) =
15881588
self.inner.session_manager.mark_device_as_wedged(&sender, curve_key).await
1589-
{
1590-
error!(
1591-
error = ?e,
1592-
"Couldn't mark device to be unwedged",
1593-
);
1594-
}
1589+
{
1590+
error!(
1591+
error = ?e,
1592+
"Couldn't mark device to be unwedged",
1593+
);
15951594
}
15961595

15971596
return Some(ProcessedToDeviceEvent::UnableToDecrypt {

crates/matrix-sdk-crypto/src/olm/account.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1700,15 +1700,14 @@ impl Account {
17001700
DeviceLinkProblem::MissingDevice,
17011701
)));
17021702

1703-
let encryption_info = EncryptionInfo {
1703+
EncryptionInfo {
17041704
sender: sender_id.to_owned(),
17051705
sender_device: sender_device.as_ref().map(|d| d.device_id().to_owned()),
17061706
algorithm_info: AlgorithmInfo::OlmV1Curve25519AesSha2 {
17071707
curve25519_public_key_base64: sender_key.to_base64(),
17081708
},
17091709
verification_state,
1710-
};
1711-
encryption_info
1710+
}
17121711
}
17131712

17141713
/// If the plaintext of the decrypted message includes a

crates/matrix-sdk-crypto/src/olm/group_sessions/inbound.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -629,12 +629,10 @@ impl InboundGroupSession {
629629

630630
if let Some(decrypted_content) =
631631
decrypted_object.get_mut("content").and_then(|c| c.as_object_mut())
632+
&& !decrypted_content.contains_key("m.relates_to")
633+
&& let Some(relation) = &event.content.relates_to
632634
{
633-
if !decrypted_content.contains_key("m.relates_to") {
634-
if let Some(relation) = &event.content.relates_to {
635-
decrypted_content.insert("m.relates_to".to_owned(), relation.to_owned());
636-
}
637-
}
635+
decrypted_content.insert("m.relates_to".to_owned(), relation.to_owned());
638636
}
639637

640638
Ok((decrypted_object, decrypted.message_index))

crates/matrix-sdk-crypto/src/secret_storage.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -495,15 +495,13 @@ impl SecretStorageKey {
495495
bytes.zeroize();
496496

497497
// The string is formatted into groups of four characters separated by spaces.
498-
let ret = base_58
498+
base_58
499499
.chars()
500500
.collect::<Vec<char>>()
501501
.chunks(DISPLAY_CHUNK_SIZE)
502502
.map(|c| c.iter().collect::<String>())
503503
.collect::<Vec<_>>()
504-
.join(" ");
505-
506-
ret
504+
.join(" ")
507505
}
508506

509507
/// Encrypt a given secret string as a Secrets Storage secret with the

crates/matrix-sdk-crypto/src/session_manager/group_sessions/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1297,10 +1297,10 @@ mod tests {
12971297
let withheld: RoomKeyWithheldContent =
12981298
content.deserialize_as_unchecked::<RoomKeyWithheldContent>().unwrap();
12991299

1300-
if let MegolmV1AesSha2(content) = withheld {
1301-
if content.withheld_code() == code {
1302-
count += 1;
1303-
}
1300+
if let MegolmV1AesSha2(content) = withheld
1301+
&& content.withheld_code() == code
1302+
{
1303+
count += 1;
13041304
}
13051305
})
13061306
}

crates/matrix-sdk-crypto/src/session_manager/group_sessions/share_strategy.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -388,14 +388,11 @@ fn update_recipients_for_user(
388388
// rotated for other reasons, we also need to check whether any
389389
// of the devices in the session got deleted or blacklisted in the
390390
// meantime. If so, we should also rotate the session.
391-
if let Some(outbound) = outbound {
392-
if !recipients.should_rotate {
393-
recipients.should_rotate = is_session_overshared_for_user(
394-
outbound,
395-
user_id,
396-
&recipient_devices.allowed_devices,
397-
)
398-
}
391+
if let Some(outbound) = outbound
392+
&& !recipients.should_rotate
393+
{
394+
recipients.should_rotate =
395+
is_session_overshared_for_user(outbound, user_id, &recipient_devices.allowed_devices)
399396
}
400397

401398
recipients

crates/matrix-sdk-crypto/src/session_manager/sessions.rs

Lines changed: 42 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -106,30 +106,30 @@ impl SessionManager {
106106
sender: &UserId,
107107
curve_key: Curve25519PublicKey,
108108
) -> OlmResult<()> {
109-
if let Some(device) = self.store.get_device_from_curve_key(sender, curve_key).await? {
110-
if let Some(session) = device.get_most_recent_session().await? {
111-
info!(sender_key = ?curve_key, "Marking session to be unwedged");
112-
113-
let creation_time = Duration::from_secs(session.creation_time.get().into());
114-
let now = Duration::from_secs(SecondsSinceUnixEpoch::now().get().into());
115-
116-
let should_unwedge = now
117-
.checked_sub(creation_time)
118-
.map(|elapsed| elapsed > Self::UNWEDGING_INTERVAL)
119-
.unwrap_or(true);
120-
121-
if should_unwedge {
122-
self.users_for_key_claim
123-
.write()
124-
.entry(device.user_id().to_owned())
125-
.or_default()
126-
.insert(device.device_id().into());
127-
self.wedged_devices
128-
.write()
129-
.entry(device.user_id().to_owned())
130-
.or_default()
131-
.insert(device.device_id().into());
132-
}
109+
if let Some(device) = self.store.get_device_from_curve_key(sender, curve_key).await?
110+
&& let Some(session) = device.get_most_recent_session().await?
111+
{
112+
info!(sender_key = ?curve_key, "Marking session to be unwedged");
113+
114+
let creation_time = Duration::from_secs(session.creation_time.get().into());
115+
let now = Duration::from_secs(SecondsSinceUnixEpoch::now().get().into());
116+
117+
let should_unwedge = now
118+
.checked_sub(creation_time)
119+
.map(|elapsed| elapsed > Self::UNWEDGING_INTERVAL)
120+
.unwrap_or(true);
121+
122+
if should_unwedge {
123+
self.users_for_key_claim
124+
.write()
125+
.entry(device.user_id().to_owned())
126+
.or_default()
127+
.insert(device.device_id().into());
128+
self.wedged_devices
129+
.write()
130+
.entry(device.user_id().to_owned())
131+
.or_default()
132+
.insert(device.device_id().into());
133133
}
134134
}
135135

@@ -148,29 +148,26 @@ impl SessionManager {
148148
///
149149
/// If the device was wedged this will queue up a dummy to-device message.
150150
async fn check_if_unwedged(&self, user_id: &UserId, device_id: &DeviceId) -> OlmResult<()> {
151-
if self.wedged_devices.write().get_mut(user_id).is_some_and(|d| d.remove(device_id)) {
152-
if let Some(device) = self.store.get_device(user_id, device_id).await? {
153-
let (_, content) =
154-
device.encrypt("m.dummy", ToDeviceDummyEventContent::new()).await?;
155-
156-
let event_type = content.event_type().to_owned();
157-
158-
let request = ToDeviceRequest::new(
159-
device.user_id(),
160-
device.device_id().to_owned(),
161-
&event_type,
162-
content.cast(),
163-
);
151+
if self.wedged_devices.write().get_mut(user_id).is_some_and(|d| d.remove(device_id))
152+
&& let Some(device) = self.store.get_device(user_id, device_id).await?
153+
{
154+
let (_, content) = device.encrypt("m.dummy", ToDeviceDummyEventContent::new()).await?;
164155

165-
let request = OutgoingRequest {
166-
request_id: request.txn_id.clone(),
167-
request: Arc::new(request.into()),
168-
};
156+
let event_type = content.event_type().to_owned();
169157

170-
self.outgoing_to_device_requests
171-
.write()
172-
.insert(request.request_id.clone(), request);
173-
}
158+
let request = ToDeviceRequest::new(
159+
device.user_id(),
160+
device.device_id().to_owned(),
161+
&event_type,
162+
content.cast(),
163+
);
164+
165+
let request = OutgoingRequest {
166+
request_id: request.txn_id.clone(),
167+
request: Arc::new(request.into()),
168+
};
169+
170+
self.outgoing_to_device_requests.write().insert(request.request_id.clone(), request);
174171
}
175172

176173
Ok(())

crates/matrix-sdk-crypto/src/store/crypto_store_wrapper.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -227,14 +227,12 @@ impl CryptoStoreWrapper {
227227
.await?
228228
.as_ref()
229229
.and_then(|i| i.other())
230+
&& !other_identity.was_previously_verified()
231+
&& own_identity_after.is_identity_signed(other_identity)
230232
{
231-
if !other_identity.was_previously_verified()
232-
&& own_identity_after.is_identity_signed(other_identity)
233-
{
234-
trace!(?tracked_user.user_id, "Marking set verified_latch to true.");
235-
other_identity.mark_as_previously_verified();
236-
updated_identities.push(other_identity.clone().into());
237-
}
233+
trace!(?tracked_user.user_id, "Marking set verified_latch to true.");
234+
other_identity.mark_as_previously_verified();
235+
updated_identities.push(other_identity.clone().into());
238236
}
239237
}
240238

0 commit comments

Comments
 (0)