Skip to content

Commit

Permalink
chore: update crypto-ffi for 2024 edition
Browse files Browse the repository at this point in the history
  • Loading branch information
coriolinus committed Feb 21, 2025
1 parent f923f6e commit 4d443db
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 37 deletions.
2 changes: 1 addition & 1 deletion crypto-ffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "core-crypto-ffi"
description = "Platform-specific bindings (Android, iOS, WASM) for CoreCrypto"
repository = "https://github.com/wireapp/core-crypto"
version = "4.1.0"
edition = "2021"
edition = "2024"
license = "GPL-3.0-only"
publish = false

Expand Down
8 changes: 4 additions & 4 deletions crypto-ffi/src/generic/context/e2ei.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use std::{collections::HashMap, ops::DerefMut};

use crate::{
CoreCryptoError, NewCrlDistributionPoints,
generic::{
context::CoreCryptoContext, Ciphersuite, ClientId, CoreCryptoResult, CrlRegistration, E2eiConversationState,
E2eiDumpedPkiEnv, E2eiEnrollment, MlsCredentialType, WireIdentity,
Ciphersuite, ClientId, CoreCryptoResult, CrlRegistration, E2eiConversationState, E2eiDumpedPkiEnv,
E2eiEnrollment, MlsCredentialType, WireIdentity, context::CoreCryptoContext,
},
CoreCryptoError, NewCrlDistributionPoints,
};
use core_crypto::{prelude::VerifiableGroupInfo, RecursiveError};
use core_crypto::{RecursiveError, prelude::VerifiableGroupInfo};
use tls_codec::Deserialize;

#[uniffi::export]
Expand Down
2 changes: 1 addition & 1 deletion crypto-ffi/src/generic/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ use super::{
use crate::NewCrlDistributionPoints;
use async_lock::{Mutex, OnceCell};
use core_crypto::{
RecursiveError,
context::CentralContext,
prelude::{
ClientIdentifier, ConversationId, KeyPackageIn, KeyPackageRef, MlsConversationConfiguration,
VerifiableGroupInfo,
},
RecursiveError,
};
use std::{future::Future, ops::Deref, sync::Arc};
use tls_codec::{Deserialize, Serialize};
Expand Down
2 changes: 1 addition & 1 deletion crypto-ffi/src/generic/context/proteus.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::ProteusAutoPrekeyBundle;
use crate::context::CoreCryptoContext;
use crate::generic::CoreCryptoResult;
use crate::proteus_impl;
use crate::ProteusAutoPrekeyBundle;

#[uniffi::export]
impl CoreCryptoContext {
Expand Down
39 changes: 22 additions & 17 deletions crypto-ffi/src/generic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,22 @@ use std::{
};

use log::{
kv::{self, Key, Value, VisitSource},
Level, LevelFilter, Metadata, Record,
kv::{self, Key, Value, VisitSource},
};
use log_reload::ReloadLog;
use tls_codec::Deserialize;

use self::context::CoreCryptoContext;
use crate::{proteus_impl, UniffiCustomTypeConverter};
use crate::{UniffiCustomTypeConverter, proteus_impl};
pub use core_crypto::prelude::ConversationId;
use core_crypto::{
InnermostErrorMessage, RecursiveError,
prelude::{
EntropySeed, MlsBufferedConversationDecryptMessage, MlsCentral, MlsCentralConfiguration, MlsCiphersuite,
MlsCommitBundle, MlsConversationDecryptMessage, MlsCustomConfiguration, MlsGroupInfoBundle, MlsProposalBundle,
VerifiableGroupInfo,
},
InnermostErrorMessage, RecursiveError,
};

pub mod context;
Expand Down Expand Up @@ -97,7 +97,9 @@ pub enum MlsError {
BufferedFutureMessage,
#[error("Incoming message is from an epoch too far in the future to buffer.")]
WrongEpoch,
#[error("Incoming message is a commit for which we have not yet received all the proposals. Buffering until all proposals have arrived.")]
#[error(
"Incoming message is a commit for which we have not yet received all the proposals. Buffering until all proposals have arrived."
)]
BufferedCommit,
#[error("The epoch in which message was encrypted is older than allowed")]
MessageEpochTooOld,
Expand All @@ -115,7 +117,9 @@ pub enum MlsError {
/// requests their old KeyPackages to be deleted but one has already been claimed by another client to create a Welcome.
/// In that case the only solution is that the client receiving such a Welcome tries to join the group
/// with an External Commit instead
#[error("Although this Welcome seems valid, the local KeyPackage it references has already been deleted locally. Join this group with an external commit")]
#[error(
"Although this Welcome seems valid, the local KeyPackage it references has already been deleted locally. Join this group with an external commit"
)]
OrphanWelcome,
/// Message rejected by the delivery service
#[error("Message rejected by the delivery service. Reason: {reason}")]
Expand Down Expand Up @@ -258,7 +262,7 @@ impl From<RecursiveError> for CoreCryptoError {
/// Hopefully only ever use this in conjunction with `interior_matches!`, because for most sane
/// circumstances, `if let` is the better design pattern.
macro_rules! matches_option {
($val:expr, $pattern:pat $(if $guard:expr)? => $out:expr) => {
($val:expr_2021, $pattern:pat $(if $guard:expr_2021)? => $out:expr_2021) => {
match ($val) {
$pattern $(if $guard)? => Some($out),
_ => None,
Expand All @@ -270,9 +274,9 @@ impl From<RecursiveError> for CoreCryptoError {
/// it solves a real problem here: how do we match against the innermost error variants,
/// when we have a heterogenous set of types to match against?
macro_rules! match_heterogenous {
($err:expr => {
$( $pattern:pat $(if $guard:expr)? => $var:expr, )*
||=> $default:expr,
($err:expr_2021 => {
$( $pattern:pat $(if $guard:expr_2021)? => $var:expr_2021, )*
||=> $default:expr_2021,
}) => {{
if false {unreachable!()}
$(
Expand Down Expand Up @@ -695,14 +699,15 @@ impl TryFrom<MlsConversationDecryptMessage> for DecryptedMessage {
.map(ProposalBundle::try_from)
.collect::<CoreCryptoResult<Vec<_>>>()?;

let buffered_messages = if let Some(bm) = from.buffered_messages {
let bm = bm
.into_iter()
.map(TryInto::try_into)
.collect::<CoreCryptoResult<Vec<_>>>()?;
Some(bm)
} else {
None
let buffered_messages = match from.buffered_messages {
Some(bm) => {
let bm = bm
.into_iter()
.map(TryInto::try_into)
.collect::<CoreCryptoResult<Vec<_>>>()?;
Some(bm)
}
_ => None,
};

Ok(Self {
Expand Down
6 changes: 3 additions & 3 deletions crypto-ffi/src/wasm/context/e2ei.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ use std::{
};

use core_crypto::{
prelude::{CiphersuiteName, ClientId, ConversationId, MlsCiphersuite, VerifiableGroupInfo},
RecursiveError,
prelude::{CiphersuiteName, ClientId, ConversationId, MlsCiphersuite, VerifiableGroupInfo},
};
use futures_util::TryFutureExt;
use js_sys::{Promise, Uint8Array};
use tls_codec::Deserialize;
use wasm_bindgen::{prelude::wasm_bindgen, JsValue};
use wasm_bindgen::{JsValue, prelude::wasm_bindgen};
use wasm_bindgen_futures::future_to_promise;

use crate::{
wasm::{context::CoreCryptoContext, E2eiConversationState},
Ciphersuite, CoreCryptoError, CredentialType, CrlRegistration, E2eiDumpedPkiEnv, E2eiEnrollment, InternalError,
WasmCryptoResult, WireIdentity,
wasm::{E2eiConversationState, context::CoreCryptoContext},
};

#[wasm_bindgen]
Expand Down
6 changes: 3 additions & 3 deletions crypto-ffi/src/wasm/context/mod.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
use crate::wasm::{lower_ciphersuites, InternalError};
use crate::wasm::{InternalError, lower_ciphersuites};
use crate::{
Ciphersuite, ConversationConfiguration, CoreCrypto, CoreCryptoError, CoreCryptoResult, CredentialType,
CustomConfiguration, DecryptedMessage, FfiClientId, WasmCryptoResult, WelcomeBundle,
};
use core_crypto::{
RecursiveError,
context::CentralContext,
prelude::{
CiphersuiteName, ClientId, ClientIdentifier, ConversationId, KeyPackageIn, KeyPackageRef,
MlsConversationConfiguration, VerifiableGroupInfo,
},
RecursiveError,
};
use futures_util::TryFutureExt;
use js_sys::{Promise, Uint8Array};
use std::sync::Arc;
use tls_codec::{Deserialize, Serialize};
use wasm_bindgen::{prelude::wasm_bindgen, JsValue};
use wasm_bindgen::{JsValue, prelude::wasm_bindgen};
use wasm_bindgen_futures::future_to_promise;

pub mod e2ei;
Expand Down
4 changes: 2 additions & 2 deletions crypto-ffi/src/wasm/context/proteus.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use crate::proteus_impl;
use crate::wasm::context::CoreCryptoContext;
use crate::wasm::CoreCryptoError;
use crate::wasm::context::CoreCryptoContext;
use crate::{ProteusAutoPrekeyBundle, WasmCryptoResult};
use futures_util::TryFutureExt;
use js_sys::{Promise, Uint8Array};
use wasm_bindgen::prelude::wasm_bindgen;
use wasm_bindgen::JsValue;
use wasm_bindgen::prelude::wasm_bindgen;
use wasm_bindgen_futures::future_to_promise;

#[wasm_bindgen]
Expand Down
14 changes: 9 additions & 5 deletions crypto-ffi/src/wasm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ use std::{
};

use crate::proteus_impl;
use core_crypto::{prelude::*, InnermostErrorMessage, MlsTransportResponse};
use core_crypto::{InnermostErrorMessage, MlsTransportResponse, prelude::*};
use futures_util::future::TryFutureExt;
use js_sys::{Promise, Uint8Array};
use log::{
kv::{self, Key, Value, VisitSource},
Level, LevelFilter, Metadata, Record,
kv::{self, Key, Value, VisitSource},
};
use log_reload::ReloadLog;
use tls_codec::Deserialize;
use utils::*;
use wasm_bindgen::{prelude::*, JsCast};
use wasm_bindgen::{JsCast, prelude::*};
use wasm_bindgen_futures::future_to_promise;

#[allow(dead_code)]
Expand Down Expand Up @@ -90,7 +90,9 @@ pub enum MlsError {
BufferedFutureMessage,
#[error("Incoming message is from an epoch too far in the future to buffer.")]
WrongEpoch,
#[error("Incoming message is a commit for which we have not yet received all the proposals. Buffering until all proposals have arrived.")]
#[error(
"Incoming message is a commit for which we have not yet received all the proposals. Buffering until all proposals have arrived."
)]
BufferedCommit,
#[error("The epoch in which message was encrypted is older than allowed")]
MessageEpochTooOld,
Expand All @@ -108,7 +110,9 @@ pub enum MlsError {
/// requests their old KeyPackages to be deleted but one has already been claimed by another client to create a Welcome.
/// In that case the only solution is that the client receiving such a Welcome tries to join the group
/// with an External Commit instead
#[error("Although this Welcome seems valid, the local KeyPackage it references has already been deleted locally. Join this group with an external commit")]
#[error(
"Although this Welcome seems valid, the local KeyPackage it references has already been deleted locally. Join this group with an external commit"
)]
OrphanWelcome,
/// Message rejected by the delivery service
#[error("Message rejected by the delivery service. Reason: {reason}")]
Expand Down

0 comments on commit 4d443db

Please sign in to comment.