Skip to content

Upgrade bindings to Rust edition 2024 #5308

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bindings/matrix-sdk-crypto-ffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "matrix-sdk-crypto-ffi"
version = "0.1.0"
authors = ["Damir Jelić <poljar@termina.org.uk>"]
edition = "2021"
edition = "2024"
rust-version.workspace = true
description = "Uniffi based bindings for the Rust SDK crypto crate"
repository = "https://github.com/matrix-org/matrix-rust-sdk"
Expand Down
4 changes: 2 additions & 2 deletions bindings/matrix-sdk-crypto-ffi/src/backup_recovery_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ use std::{collections::HashMap, iter, ops::DerefMut, sync::Arc};
use hmac::Hmac;
use matrix_sdk_crypto::{
backups::DecryptionError,
store::{types::BackupDecryptionKey, CryptoStoreError as InnerStoreError},
store::{CryptoStoreError as InnerStoreError, types::BackupDecryptionKey},
};
use pbkdf2::pbkdf2;
use rand::{distributions::Alphanumeric, thread_rng, Rng};
use rand::{Rng, distributions::Alphanumeric, thread_rng};
use sha2::Sha512;
use thiserror::Error;
use zeroize::Zeroize;
Expand Down
4 changes: 2 additions & 2 deletions bindings/matrix-sdk-crypto-ffi/src/dehydrated_devices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use matrix_sdk_crypto::{
},
store::types::DehydratedDeviceKey as InnerDehydratedDeviceKey,
};
use ruma::{api::client::dehydrated_device, events::AnyToDeviceEvent, serde::Raw, OwnedDeviceId};
use ruma::{OwnedDeviceId, api::client::dehydrated_device, events::AnyToDeviceEvent, serde::Raw};
use serde_json::json;

use crate::{CryptoStoreError, DehydratedDeviceKey};
Expand Down Expand Up @@ -222,7 +222,7 @@ impl From<dehydrated_device::put_dehydrated_device::unstable::Request>

#[cfg(test)]
mod tests {
use crate::{dehydrated_devices::DehydrationError, DehydratedDeviceKey};
use crate::{DehydratedDeviceKey, dehydrated_devices::DehydrationError};

#[test]
fn test_creating_dehydrated_key() {
Expand Down
2 changes: 1 addition & 1 deletion bindings/matrix-sdk-crypto-ffi/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#![allow(missing_docs)]

use matrix_sdk_crypto::{
store::{CryptoStoreError as InnerStoreError, DehydrationError as InnerDehydrationError},
KeyExportError, MegolmError, OlmError, SecretImportError as RustSecretImportError,
SignatureError as InnerSignatureError,
store::{CryptoStoreError as InnerStoreError, DehydrationError as InnerDehydrationError},
};
use matrix_sdk_sqlite::OpenStoreError;
use ruma::{IdParseError, OwnedUserId};
Expand Down
12 changes: 6 additions & 6 deletions bindings/matrix-sdk-crypto-ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,32 +31,32 @@ pub use error::{
CryptoStoreError, DecryptionError, KeyImportError, SecretImportError, SignatureError,
};
use js_int::UInt;
pub use logger::{set_logger, Logger};
pub use logger::{Logger, set_logger};
pub use machine::{KeyRequestPair, OlmMachine, SignatureVerification};
use matrix_sdk_common::deserialized_responses::{ShieldState as RustShieldState, ShieldStateCode};
use matrix_sdk_crypto::{
CollectStrategy, EncryptionSettings as RustEncryptionSettings,
olm::{IdentityKeys, InboundGroupSession, SenderData, Session},
store::{
CryptoStore,
types::{
Changes, DehydratedDeviceKey as InnerDehydratedDeviceKey, PendingChanges,
RoomSettings as RustRoomSettings,
},
CryptoStore,
},
types::{
DeviceKey, DeviceKeys, EventEncryptionAlgorithm as RustEventEncryptionAlgorithm, SigningKey,
},
CollectStrategy, EncryptionSettings as RustEncryptionSettings,
};
use matrix_sdk_sqlite::SqliteCryptoStore;
pub use responses::{
BootstrapCrossSigningResult, DeviceLists, KeysImportResult, OutgoingVerificationRequest,
Request, RequestType, SignatureUploadRequest, UploadSigningKeysRequest,
};
use ruma::{
events::room::history_visibility::HistoryVisibility as RustHistoryVisibility,
DeviceKeyAlgorithm, DeviceKeyId, MilliSecondsSinceUnixEpoch, OwnedDeviceId, OwnedUserId,
RoomId, SecondsSinceUnixEpoch, UserId,
events::room::history_visibility::HistoryVisibility as RustHistoryVisibility,
};
use serde::{Deserialize, Serialize};
use tokio::runtime::Runtime;
Expand Down Expand Up @@ -1034,11 +1034,11 @@ uniffi::setup_scaffolding!();
#[cfg(test)]
mod tests {
use anyhow::Result;
use serde_json::{json, Value};
use serde_json::{Value, json};
use tempfile::tempdir;

use super::MigrationData;
use crate::{migrate, EventEncryptionAlgorithm, OlmMachine, RoomSettings};
use crate::{EventEncryptionAlgorithm, OlmMachine, RoomSettings, migrate};

#[test]
fn android_migration() -> Result<()> {
Expand Down
2 changes: 1 addition & 1 deletion bindings/matrix-sdk-crypto-ffi/src/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{
sync::{Arc, Mutex},
};

use tracing_subscriber::{fmt::MakeWriter, EnvFilter};
use tracing_subscriber::{EnvFilter, fmt::MakeWriter};

/// Trait that can be used to forward Rust logs over FFI to a language specific
/// logger.
Expand Down
24 changes: 12 additions & 12 deletions bindings/matrix-sdk-crypto-ffi/src/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use std::{
use js_int::UInt;
use matrix_sdk_common::deserialized_responses::AlgorithmInfo;
use matrix_sdk_crypto::{
DecryptionSettings, LocalTrust, OlmMachine as InnerMachine, UserIdentity as SdkUserIdentity,
backups::{
MegolmV1BackupKey as RustBackupKey, SignatureState,
SignatureVerification as RustSignatureCheckResult,
Expand All @@ -18,10 +19,12 @@ use matrix_sdk_crypto::{
olm::ExportedRoomKey,
store::types::{BackupDecryptionKey, Changes},
types::requests::ToDeviceRequest,
DecryptionSettings, LocalTrust, OlmMachine as InnerMachine, UserIdentity as SdkUserIdentity,
};
use ruma::{
DeviceKeyAlgorithm, EventId, OneTimeKeyAlgorithm, OwnedTransactionId, OwnedUserId, RoomId,
UserId,
api::{
IncomingResponse,
client::{
backup::add_backup_keys::v3::Response as KeysBackupResponse,
keys::{
Expand All @@ -31,35 +34,32 @@ use ruma::{
upload_signatures::v3::Response as SignatureUploadResponse,
},
message::send_message_event::v3::Response as RoomMessageResponse,
sync::sync_events::{v3::ToDevice, DeviceLists as RumaDeviceLists},
sync::sync_events::{DeviceLists as RumaDeviceLists, v3::ToDevice},
to_device::send_event_to_device::v3::Response as ToDeviceResponse,
},
IncomingResponse,
},
events::{
key::verification::VerificationMethod, room::message::MessageType, AnyMessageLikeEvent,
AnySyncMessageLikeEvent, MessageLikeEvent,
AnyMessageLikeEvent, AnySyncMessageLikeEvent, MessageLikeEvent,
key::verification::VerificationMethod, room::message::MessageType,
},
serde::Raw,
to_device::DeviceIdOrAllDevices,
DeviceKeyAlgorithm, EventId, OneTimeKeyAlgorithm, OwnedTransactionId, OwnedUserId, RoomId,
UserId,
};
use serde::{Deserialize, Serialize};
use serde_json::{value::RawValue, Value};
use serde_json::{Value, value::RawValue};
use tokio::runtime::Runtime;
use zeroize::Zeroize;

use crate::{
dehydrated_devices::DehydratedDevices,
error::{CryptoStoreError, DecryptionError, SecretImportError, SignatureError},
parse_user_id,
responses::{response_from_string, OwnedResponse},
BackupKeys, BackupRecoveryKey, BootstrapCrossSigningResult, CrossSigningKeyExport,
CrossSigningStatus, DecodeError, DecryptedEvent, Device, DeviceLists, EncryptionSettings,
EventEncryptionAlgorithm, KeyImportError, KeysImportResult, MegolmV1BackupKey,
ProgressListener, Request, RequestType, RequestVerificationResult, RoomKeyCounts, RoomSettings,
Sas, SignatureUploadRequest, StartSasResult, UserIdentity, Verification, VerificationRequest,
dehydrated_devices::DehydratedDevices,
error::{CryptoStoreError, DecryptionError, SecretImportError, SignatureError},
parse_user_id,
responses::{OwnedResponse, response_from_string},
};

/// The return value for the [`OlmMachine::receive_sync_changes()`] method.
Expand Down
4 changes: 2 additions & 2 deletions bindings/matrix-sdk-crypto-ffi/src/responses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ use std::collections::HashMap;

use http::Response;
use matrix_sdk_crypto::{
CrossSigningBootstrapRequests,
types::requests::{
AnyIncomingResponse, KeysBackupRequest, OutgoingRequest,
OutgoingVerificationRequest as SdkVerificationRequest, RoomMessageRequest, ToDeviceRequest,
UploadSigningKeysRequest as RustUploadSigningKeysRequest,
},
CrossSigningBootstrapRequests,
};
use ruma::{
OwnedTransactionId, UserId,
api::client::{
backup::add_backup_keys::v3::Response as KeysBackupResponse,
keys::{
Expand All @@ -28,7 +29,6 @@ use ruma::{
},
assign,
events::EventContent,
OwnedTransactionId, UserId,
};
use serde_json::json;

Expand Down
2 changes: 1 addition & 1 deletion bindings/matrix-sdk-crypto-ffi/src/users.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use matrix_sdk_crypto::{types::CrossSigningKey, UserIdentity as SdkUserIdentity};
use matrix_sdk_crypto::{UserIdentity as SdkUserIdentity, types::CrossSigningKey};

use crate::CryptoStoreError;

Expand Down
7 changes: 4 additions & 3 deletions bindings/matrix-sdk-crypto-ffi/src/verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ use std::sync::Arc;
use futures_util::{Stream, StreamExt};
use matrix_sdk_common::executor::Handle;
use matrix_sdk_crypto::{
matrix_sdk_qrcode::QrVerificationData, CancelInfo as RustCancelInfo, QrVerification as InnerQr,
QrVerificationState, Sas as InnerSas, SasState as RustSasState,
Verification as InnerVerification, VerificationRequest as InnerVerificationRequest,
CancelInfo as RustCancelInfo, QrVerification as InnerQr, QrVerificationState, Sas as InnerSas,
SasState as RustSasState, Verification as InnerVerification,
VerificationRequest as InnerVerificationRequest,
VerificationRequestState as RustVerificationRequestState,
matrix_sdk_qrcode::QrVerificationData,
};
use ruma::events::key::verification::VerificationMethod;
use vodozemac::{base64_decode, base64_encode};
Expand Down
2 changes: 1 addition & 1 deletion bindings/matrix-sdk-ffi-macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
description = "Helper macros to write FFI bindings"
edition = "2021"
edition = "2024"
homepage = "https://github.com/matrix-org/matrix-rust-sdk"
keywords = ["matrix", "chat", "messaging", "ruma"]
license = "Apache-2.0"
Expand Down
2 changes: 1 addition & 1 deletion bindings/matrix-sdk-ffi/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "matrix-sdk-ffi"
version = "0.12.0"
edition = "2021"
edition = "2024"
homepage = "https://github.com/matrix-org/matrix-rust-sdk"
keywords = ["matrix", "chat", "messaging", "ffi"]
license = "Apache-2.0"
Expand Down
4 changes: 2 additions & 2 deletions bindings/matrix-sdk-ffi/src/authentication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ use std::{
};

use matrix_sdk::{
Error,
authentication::oauth::{
ClientId, ClientRegistrationData, OAuthError as SdkOAuthError,
error::OAuthAuthorizationCodeError,
registration::{ApplicationType, ClientMetadata, Localized, OAuthGrantType},
ClientId, ClientRegistrationData, OAuthError as SdkOAuthError,
},
Error,
};
use ruma::serde::Raw;
use url::Url;
Expand Down
28 changes: 14 additions & 14 deletions bindings/matrix-sdk-ffi/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,43 +6,43 @@ use std::{
time::Duration,
};

use anyhow::{anyhow, Context as _};
use anyhow::{Context as _, anyhow};
use futures_util::pin_mut;
#[cfg(not(target_family = "wasm"))]
use matrix_sdk::media::MediaFileHandle as SdkMediaFileHandle;
use matrix_sdk::{
AuthApi, AuthSession, Client as MatrixClient, STATE_STORE_DATABASE_NAME, SessionChange,
SessionTokens,
authentication::oauth::{
AccountManagementActionFull, ClientId, OAuthAuthorizationData, OAuthSession,
},
event_cache::EventCacheError,
media::{MediaFormat, MediaRequestParameters, MediaRetentionPolicy, MediaThumbnailSettings},
ruma::{
EventEncryptionAlgorithm, RoomId, TransactionId, UInt, UserId,
api::client::{
discovery::{
discover_homeserver::RtcFocusInfo,
get_authorization_server_metadata::msc2965::Prompt as RumaOidcPrompt,
},
push::{EmailPusherData, PusherIds, PusherInit, PusherKind as RumaPusherKind},
room::{create_room, Visibility},
room::{Visibility, create_room},
session::get_login_types,
user_directory::search_users,
},
events::{
AnyInitialStateEvent, InitialStateEvent,
room::{
avatar::RoomAvatarEventContent, encryption::RoomEncryptionEventContent,
message::MessageType,
},
AnyInitialStateEvent, InitialStateEvent,
},
serde::Raw,
EventEncryptionAlgorithm, RoomId, TransactionId, UInt, UserId,
},
sliding_sync::Version as SdkSlidingSyncVersion,
store::RoomLoadSettings as SdkRoomLoadSettings,
AuthApi, AuthSession, Client as MatrixClient, SessionChange, SessionTokens,
STATE_STORE_DATABASE_NAME,
};
use matrix_sdk_common::{stream::StreamExt, SendOutsideWasm, SyncOutsideWasm};
use matrix_sdk_common::{SendOutsideWasm, SyncOutsideWasm, stream::StreamExt};
use matrix_sdk_ui::{
notification_client::{
NotificationClient as MatrixNotificationClient,
Expand All @@ -52,8 +52,12 @@ use matrix_sdk_ui::{
};
use mime::Mime;
use ruma::{
OwnedServerName, RoomAliasId, RoomOrAliasId, ServerName,
api::client::{alias::get_alias, error::ErrorKind, uiaa::UserIdentifier},
events::{
GlobalAccountDataEvent as RumaGlobalAccountDataEvent,
GlobalAccountDataEventType as RumaGlobalAccountDataEventType,
RoomAccountDataEvent as RumaRoomAccountDataEvent,
direct::DirectEventContent,
fully_read::FullyReadEventContent,
identity_server::IdentityServerEventContent,
Expand All @@ -73,24 +77,21 @@ use ruma::{
default_key::SecretStorageDefaultKeyEventContent, key::SecretStorageKeyEventContent,
},
tag::TagEventContent,
GlobalAccountDataEvent as RumaGlobalAccountDataEvent,
GlobalAccountDataEventType as RumaGlobalAccountDataEventType,
RoomAccountDataEvent as RumaRoomAccountDataEvent,
},
push::{HttpPusherData as RumaHttpPusherData, PushFormat as RumaPushFormat},
OwnedServerName, RoomAliasId, RoomOrAliasId, ServerName,
};
use serde::{Deserialize, Serialize};
use serde_json::{json, Value};
use serde_json::{Value, json};
use tokio::sync::broadcast::error::RecvError;
use tracing::{debug, error};
use url::Url;

use super::{
room::{room_info::RoomInfo, Room},
room::{Room, room_info::RoomInfo},
session_verification::SessionVerificationController,
};
use crate::{
ClientError,
authentication::{HomeserverLoginDetails, OidcConfiguration, OidcError, SsoError, SsoHandler},
client,
encryption::Encryption,
Expand All @@ -108,7 +109,6 @@ use crate::{
task_handle::TaskHandle,
utd::{UnableToDecryptDelegate, UtdHook},
utils::AsyncRuntimeDropped,
ClientError,
};

#[derive(Clone, uniffi::Record)]
Expand Down
6 changes: 3 additions & 3 deletions bindings/matrix-sdk-ffi/src/client_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ use futures_util::StreamExt;
#[cfg(not(target_family = "wasm"))]
use matrix_sdk::reqwest::Certificate;
use matrix_sdk::{
Client as MatrixClient, ClientBuildError as MatrixClientBuildError, HttpError, IdParseError,
RumaApiError, SqliteStoreConfig,
crypto::{
types::qr_login::QrCodeModeData, CollectStrategy, DecryptionSettings, TrustRequirement,
CollectStrategy, DecryptionSettings, TrustRequirement, types::qr_login::QrCodeModeData,
},
encryption::{BackupDownloadStrategy, EncryptionSettings},
event_cache::EventCacheError,
Expand All @@ -14,8 +16,6 @@ use matrix_sdk::{
Error as MatrixSlidingSyncError, VersionBuilder as MatrixSlidingSyncVersionBuilder,
VersionBuilderError,
},
Client as MatrixClient, ClientBuildError as MatrixClientBuildError, HttpError, IdParseError,
RumaApiError, SqliteStoreConfig,
};
use ruma::api::error::{DeserializationError, FromHttpResponseError};
use tracing::{debug, error};
Expand Down
8 changes: 4 additions & 4 deletions bindings/matrix-sdk-ffi/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
use std::{collections::HashMap, error::Error, fmt, fmt::Display};

use matrix_sdk::{
HttpError, IdParseError, NotificationSettingsError as SdkNotificationSettingsError,
QueueWedgeError as SdkQueueWedgeError, StoreError,
authentication::oauth::OAuthError,
encryption::{identities::RequestVerificationError, CryptoStoreError},
encryption::{CryptoStoreError, identities::RequestVerificationError},
event_cache::EventCacheError,
reqwest,
room::edit::EditError,
send_queue::RoomSendQueueError,
HttpError, IdParseError, NotificationSettingsError as SdkNotificationSettingsError,
QueueWedgeError as SdkQueueWedgeError, StoreError,
};
use matrix_sdk_ui::{encryption_sync_service, notification_client, sync_service, timeline};
use ruma::{
api::client::error::{ErrorBody, ErrorKind as RumaApiErrorKind, RetryAfter},
MilliSecondsSinceUnixEpoch,
api::client::error::{ErrorBody, ErrorKind as RumaApiErrorKind, RetryAfter},
};
use tracing::warn;
use uniffi::UnexpectedUniFFICallbackError;
Expand Down
Loading
Loading