mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-05-06 15:04:11 -04:00
crypto-ffi: Use proc-macro for exporting free functions
This commit is contained in:
committed by
Jonas Platte
parent
f8e4e3d7d5
commit
d15447a2c1
@@ -188,15 +188,16 @@ impl From<anyhow::Error> for MigrationError {
|
||||
///
|
||||
/// * `progress_listener` - A callback that can be used to introspect the
|
||||
/// progress of the migration.
|
||||
#[uniffi::export]
|
||||
pub fn migrate(
|
||||
data: MigrationData,
|
||||
path: &str,
|
||||
path: String,
|
||||
passphrase: Option<String>,
|
||||
progress_listener: Box<dyn ProgressListener>,
|
||||
) -> Result<(), MigrationError> {
|
||||
let runtime = Runtime::new().context("initializing tokio runtime")?;
|
||||
runtime.block_on(async move {
|
||||
migrate_data(data, path, passphrase, progress_listener).await?;
|
||||
migrate_data(data, &path, passphrase, progress_listener).await?;
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
@@ -350,14 +351,15 @@ async fn save_changes(
|
||||
///
|
||||
/// * `progress_listener` - A callback that can be used to introspect the
|
||||
/// progress of the migration.
|
||||
#[uniffi::export]
|
||||
pub fn migrate_sessions(
|
||||
data: SessionMigrationData,
|
||||
path: &str,
|
||||
path: String,
|
||||
passphrase: Option<String>,
|
||||
progress_listener: Box<dyn ProgressListener>,
|
||||
) -> Result<(), MigrationError> {
|
||||
let runtime = Runtime::new().context("initializing tokio runtime")?;
|
||||
runtime.block_on(migrate_session_data(data, path, passphrase, progress_listener))?;
|
||||
runtime.block_on(migrate_session_data(data, &path, passphrase, progress_listener))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -497,9 +499,10 @@ fn collect_sessions(
|
||||
/// * `passphrase` - The passphrase that should be used to encrypt the data at
|
||||
/// rest in the Sqlite store. **Warning**, if no passphrase is given, the store
|
||||
/// and all its data will remain unencrypted.
|
||||
#[uniffi::export]
|
||||
pub fn migrate_room_settings(
|
||||
room_settings: HashMap<String, RoomSettings>,
|
||||
path: &str,
|
||||
path: String,
|
||||
passphrase: Option<String>,
|
||||
) -> Result<(), MigrationError> {
|
||||
let runtime = Runtime::new().context("initializing tokio runtime")?;
|
||||
@@ -959,12 +962,15 @@ mod test {
|
||||
let migration_data: MigrationData = serde_json::from_value(data)?;
|
||||
|
||||
let dir = tempdir()?;
|
||||
let path =
|
||||
dir.path().to_str().expect("Creating a string from the tempdir path should not fail");
|
||||
let path = dir
|
||||
.path()
|
||||
.to_str()
|
||||
.expect("Creating a string from the tempdir path should not fail")
|
||||
.to_owned();
|
||||
|
||||
migrate(migration_data, path, None, Box::new(|_, _| {}))?;
|
||||
migrate(migration_data, path.clone(), None, Box::new(|_, _| {}))?;
|
||||
|
||||
let machine = OlmMachine::new("@ganfra146:matrix.org", "DEWRCMENGS", path, None)?;
|
||||
let machine = OlmMachine::new("@ganfra146:matrix.org", "DEWRCMENGS", &path, None)?;
|
||||
|
||||
assert_eq!(
|
||||
machine.identity_keys()["ed25519"],
|
||||
|
||||
@@ -41,6 +41,7 @@ pub struct LoggerWrapper {
|
||||
}
|
||||
|
||||
/// Set the logger that should be used to forward Rust logs over FFI.
|
||||
#[uniffi::export]
|
||||
pub fn set_logger(logger: Box<dyn Logger>) {
|
||||
let logger = LoggerWrapper { inner: Arc::new(Mutex::new(logger)) };
|
||||
|
||||
|
||||
@@ -1,26 +1,4 @@
|
||||
namespace matrix_sdk_crypto_ffi {
|
||||
void set_logger(Logger logger);
|
||||
[Throws=MigrationError]
|
||||
void migrate(
|
||||
MigrationData data,
|
||||
[ByRef] string path,
|
||||
string? passphrase,
|
||||
ProgressListener progress_listener
|
||||
);
|
||||
[Throws=MigrationError]
|
||||
void migrate_sessions(
|
||||
SessionMigrationData data,
|
||||
[ByRef] string path,
|
||||
string? passphrase,
|
||||
ProgressListener progress_listener
|
||||
);
|
||||
[Throws=MigrationError]
|
||||
void migrate_room_settings(
|
||||
record<string, RoomSettings> room_settings,
|
||||
[ByRef] string path,
|
||||
string? passphrase
|
||||
);
|
||||
};
|
||||
namespace matrix_sdk_crypto_ffi {};
|
||||
|
||||
[Error]
|
||||
interface MigrationError {
|
||||
|
||||
Reference in New Issue
Block a user