Skip to content

Commit 6c7acf6

Browse files
committed
ffi: Expose the master_key method on UserIdentity
1 parent 181ee64 commit 6c7acf6

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

bindings/matrix-sdk-ffi/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@ Breaking changes:
3131

3232
Additions:
3333

34-
- Add `Encryption::get_user_identity`
34+
- Add `Encryption::get_user_identity` which returns `UserIdentity`
3535
- Add `ClientBuilder::room_key_recipient_strategy`

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

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -413,19 +413,16 @@ impl Encryption {
413413

414414
/// Get the E2EE identity of a user.
415415
///
416-
/// Returns an error if this user does not exist, if there is an error
417-
/// contacting the crypto store, or if our client is not logged in.
416+
/// Returns Ok(None) if this user does not exist.
417+
///
418+
/// Returns an error if there was a problem contacting the crypto store, or
419+
/// if our client is not logged in.
418420
pub async fn get_user_identity(
419421
&self,
420422
user_id: String,
421-
) -> Result<Arc<UserIdentity>, ClientError> {
422-
Ok(Arc::new(UserIdentity {
423-
inner: self
424-
.inner
425-
.get_user_identity(user_id.as_str().try_into()?)
426-
.await?
427-
.ok_or(ClientError::new("User not found"))?,
428-
}))
423+
) -> Result<Option<Arc<UserIdentity>>, ClientError> {
424+
let identity = self.inner.get_user_identity(user_id.as_str().try_into()?).await?;
425+
Ok(identity.map(|i| Arc::new(UserIdentity { inner: i })))
429426
}
430427
}
431428

@@ -454,6 +451,16 @@ impl UserIdentity {
454451
pub(crate) async fn pin(&self) -> Result<(), ClientError> {
455452
Ok(self.inner.pin().await?)
456453
}
454+
455+
/// Get the public part of the Master key of this user identity.
456+
///
457+
/// The public part of the Master key is usually used to uniquely identify
458+
/// the identity.
459+
///
460+
/// Returns None if the master key does not actually contain any keys.
461+
pub(crate) fn master_key(&self) -> Option<String> {
462+
self.inner.master_key().get_first_key().map(|k| k.to_base64())
463+
}
457464
}
458465

459466
#[derive(uniffi::Object)]

0 commit comments

Comments
 (0)