Skip to content

Commit

Permalink
ffi: Expose the master_key method on UserIdentity
Browse files Browse the repository at this point in the history
  • Loading branch information
andybalaam committed Oct 7, 2024
1 parent 181ee64 commit 6c7acf6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
2 changes: 1 addition & 1 deletion bindings/matrix-sdk-ffi/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ Breaking changes:

Additions:

- Add `Encryption::get_user_identity`
- Add `Encryption::get_user_identity` which returns `UserIdentity`
- Add `ClientBuilder::room_key_recipient_strategy`
27 changes: 17 additions & 10 deletions bindings/matrix-sdk-ffi/src/encryption.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,19 +413,16 @@ impl Encryption {

/// Get the E2EE identity of a user.
///
/// Returns an error if this user does not exist, if there is an error
/// contacting the crypto store, or if our client is not logged in.
/// Returns Ok(None) if this user does not exist.
///
/// Returns an error if there was a problem contacting the crypto store, or
/// if our client is not logged in.
pub async fn get_user_identity(
&self,
user_id: String,
) -> Result<Arc<UserIdentity>, ClientError> {
Ok(Arc::new(UserIdentity {
inner: self
.inner
.get_user_identity(user_id.as_str().try_into()?)
.await?
.ok_or(ClientError::new("User not found"))?,
}))
) -> Result<Option<Arc<UserIdentity>>, ClientError> {
let identity = self.inner.get_user_identity(user_id.as_str().try_into()?).await?;
Ok(identity.map(|i| Arc::new(UserIdentity { inner: i })))
}
}

Expand Down Expand Up @@ -454,6 +451,16 @@ impl UserIdentity {
pub(crate) async fn pin(&self) -> Result<(), ClientError> {
Ok(self.inner.pin().await?)
}

/// Get the public part of the Master key of this user identity.
///
/// The public part of the Master key is usually used to uniquely identify
/// the identity.
///
/// Returns None if the master key does not actually contain any keys.
pub(crate) fn master_key(&self) -> Option<String> {
self.inner.master_key().get_first_key().map(|k| k.to_base64())
}
}

#[derive(uniffi::Object)]
Expand Down

0 comments on commit 6c7acf6

Please sign in to comment.