diff --git a/bindings/matrix-sdk-crypto-ffi/src/backup_recovery_key.rs b/bindings/matrix-sdk-crypto-ffi/src/backup_recovery_key.rs index bb7cce3255a..4d29a288607 100644 --- a/bindings/matrix-sdk-crypto-ffi/src/backup_recovery_key.rs +++ b/bindings/matrix-sdk-crypto-ffi/src/backup_recovery_key.rs @@ -59,6 +59,19 @@ pub struct MegolmV1BackupKey { pub backup_algorithm: String, } +#[uniffi::export] +impl BackupRecoveryKey { + /// Convert the recovery key to a base 58 encoded string. + pub fn to_base58(&self) -> String { + self.inner.to_base58() + } + + /// Convert the recovery key to a base 64 encoded string. + pub fn to_base64(&self) -> String { + self.inner.to_base64() + } +} + impl BackupRecoveryKey { const KEY_SIZE: usize = 32; const SALT_SIZE: usize = 32; @@ -134,16 +147,6 @@ impl BackupRecoveryKey { } } - /// Convert the recovery key to a base 58 encoded string. - pub fn to_base58(&self) -> String { - self.inner.to_base58() - } - - /// Convert the recovery key to a base 64 encoded string. - pub fn to_base64(&self) -> String { - self.inner.to_base64() - } - /// Try to decrypt a message that was encrypted using the public part of the /// backup key. pub fn decrypt_v1( diff --git a/bindings/matrix-sdk-crypto-ffi/src/lib.rs b/bindings/matrix-sdk-crypto-ffi/src/lib.rs index e79e3e313f7..c9111d92309 100644 --- a/bindings/matrix-sdk-crypto-ffi/src/lib.rs +++ b/bindings/matrix-sdk-crypto-ffi/src/lib.rs @@ -467,6 +467,10 @@ fn parse_user_id(user_id: &str) -> Result { ruma::UserId::parse(user_id).map_err(|e| CryptoStoreError::InvalidUserId(user_id.to_owned(), e)) } +mod uniffi_types { + pub use crate::{backup_recovery_key::BackupRecoveryKey, machine::OlmMachine}; +} + #[allow(warnings)] mod generated { use super::*; diff --git a/bindings/matrix-sdk-crypto-ffi/src/machine.rs b/bindings/matrix-sdk-crypto-ffi/src/machine.rs index c3a0d632b49..864463c798e 100644 --- a/bindings/matrix-sdk-crypto-ffi/src/machine.rs +++ b/bindings/matrix-sdk-crypto-ffi/src/machine.rs @@ -67,6 +67,28 @@ pub struct KeyRequestPair { pub key_request: Request, } +#[uniffi::export] +impl OlmMachine { + /// Get the user ID of the owner of this `OlmMachine`. + pub fn user_id(&self) -> String { + self.inner.user_id().to_string() + } + + /// Get the device ID of the device of this `OlmMachine`. + pub fn device_id(&self) -> String { + self.inner.device_id().to_string() + } + + /// Get our own identity keys. + pub fn identity_keys(&self) -> HashMap { + let identity_keys = self.inner.identity_keys(); + let curve_key = identity_keys.curve25519.to_base64(); + let ed25519_key = identity_keys.ed25519.to_base64(); + + HashMap::from([("ed25519".to_owned(), ed25519_key), ("curve25519".to_owned(), curve_key)]) + } +} + impl OlmMachine { /// Create a new `OlmMachine` /// @@ -116,16 +138,6 @@ impl OlmMachine { }) } - /// Get the user ID of the owner of this `OlmMachine`. - pub fn user_id(&self) -> String { - self.inner.user_id().to_string() - } - - /// Get the device ID of the device of this `OlmMachine`. - pub fn device_id(&self) -> String { - self.inner.device_id().to_string() - } - /// Get the display name of our own device. pub fn display_name(&self) -> Result, CryptoStoreError> { Ok(self.runtime.block_on(self.inner.display_name())?) @@ -313,15 +325,6 @@ impl OlmMachine { .collect()) } - /// Get our own identity keys. - pub fn identity_keys(&self) -> HashMap { - let identity_keys = self.inner.identity_keys(); - let curve_key = identity_keys.curve25519.to_base64(); - let ed25519_key = identity_keys.ed25519.to_base64(); - - HashMap::from([("ed25519".to_owned(), ed25519_key), ("curve25519".to_owned(), curve_key)]) - } - /// Get the list of outgoing requests that need to be sent to the /// homeserver. /// diff --git a/bindings/matrix-sdk-crypto-ffi/src/olm.udl b/bindings/matrix-sdk-crypto-ffi/src/olm.udl index 7ee0dfe04af..a30f65407ad 100644 --- a/bindings/matrix-sdk-crypto-ffi/src/olm.udl +++ b/bindings/matrix-sdk-crypto-ffi/src/olm.udl @@ -256,10 +256,6 @@ interface OlmMachine { string? passphrase ); - record identity_keys(); - string user_id(); - string device_id(); - [Throws=CryptoStoreError] string receive_sync_changes([ByRef] string events, DeviceLists device_changes, @@ -438,8 +434,6 @@ interface BackupRecoveryKey { constructor(string key); [Name=from_base58, Throws=DecodeError] constructor(string key); - string to_base58(); - string to_base64(); MegolmV1BackupKey megolm_v1_public_key(); [Throws=PkDecryptionError] string decrypt_v1(string ephemeral_key, string mac, string ciphertext);