Skip to content

Commit

Permalink
crypto: update OtherUserIdentityData::is_device_signed to return bool
Browse files Browse the repository at this point in the history
Once again: since all the callers end up calling `.is_ok()` on the result, and
the name implies it should return a bool, let's just return a bool.
  • Loading branch information
richvdh committed Aug 16, 2024
1 parent 5f9a4fc commit 96c4e4c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 14 deletions.
6 changes: 2 additions & 4 deletions crates/matrix-sdk-crypto/src/identities/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,7 @@ impl DeviceData {
// check if the other user has signed this device.
UserIdentityData::Other(device_identity) => {
own_identity.is_identity_verified(device_identity)
&& device_identity.is_device_signed(self).is_ok()
&& device_identity.is_device_signed(self)
}
}
},
Expand All @@ -769,9 +769,7 @@ impl DeviceData {
UserIdentityData::Own(identity) => identity.is_device_signed(self),
// If it's a device from someone else, check
// if the other user has signed this device.
UserIdentityData::Other(device_identity) => {
device_identity.is_device_signed(self).is_ok()
}
UserIdentityData::Other(device_identity) => device_identity.is_device_signed(self),
}
}

Expand Down
4 changes: 2 additions & 2 deletions crates/matrix-sdk-crypto/src/identities/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1458,7 +1458,7 @@ pub(crate) mod tests {
let identity = manager.store.get_user_identity(other_user).await.unwrap().unwrap();
let identity = identity.other().unwrap();

identity.is_device_signed(&device).unwrap();
assert!(identity.is_device_signed(&device));
}

#[async_test]
Expand Down Expand Up @@ -2113,7 +2113,7 @@ pub(crate) mod tests {
.await
.unwrap()
.unwrap();
assert!(bob_identity.is_device_signed(&bob_device).is_ok());
assert!(bob_identity.is_device_signed(&bob_device));
// there is also a pin violation
assert!(bob_identity.has_pin_violation());
// Fixing the pin violation won't fix the verification latch violation
Expand Down
11 changes: 3 additions & 8 deletions crates/matrix-sdk-crypto/src/identities/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -762,14 +762,9 @@ impl OtherUserIdentityData {
///
/// * `device` - The device that should be checked for a valid signature.
///
/// Returns an empty result if the signature check succeeded, otherwise a
/// SignatureError indicating why the check failed.
pub(crate) fn is_device_signed(&self, device: &DeviceData) -> Result<(), SignatureError> {
if self.user_id() != device.user_id() {
return Err(SignatureError::UserIdMismatch);
}

self.self_signing_key.verify_device(device)
/// Returns `true` if the signature check succeeded, otherwise `false`.
pub(crate) fn is_device_signed(&self, device: &DeviceData) -> bool {
self.user_id() == device.user_id() && self.self_signing_key.verify_device(device).is_ok()
}
}

Expand Down

0 comments on commit 96c4e4c

Please sign in to comment.