Skip to content

Commit

Permalink
style: run cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonThormeyer committed Oct 24, 2024
1 parent 766aecc commit 77ca951
Show file tree
Hide file tree
Showing 75 changed files with 2,378 additions and 3,226 deletions.
16 changes: 8 additions & 8 deletions crypto-ffi/src/generic/context/mod.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
use std::{ops::Deref, sync::Arc};
use std::sync::atomic::AtomicU32;
use super::{
BufferedDecryptedMessage, Ciphersuite, Ciphersuites, ClientId, CommitBundle, ConversationConfiguration,
ConversationInitBundle, CoreCrypto, CoreCryptoError, CoreCryptoResult, CustomConfiguration, DecryptedMessage,
MemberAddedMessages, MlsCredentialType, ProposalBundle, WelcomeBundle,
};
use core_crypto::context::CentralContext;
use core_crypto::{
prelude::{
ClientIdentifier, ConversationId, KeyPackageIn, KeyPackageRef, MlsConversationConfiguration,
VerifiableGroupInfo,
},
CryptoError, MlsError,
};
use std::sync::atomic::AtomicU32;
use std::{ops::Deref, sync::Arc};
use tls_codec::{Deserialize, Serialize};
use core_crypto::context::CentralContext;
use super::{
BufferedDecryptedMessage, Ciphersuite, Ciphersuites, ClientId, CommitBundle, ConversationConfiguration,
ConversationInitBundle, CoreCrypto, CoreCryptoError, CoreCryptoResult, CustomConfiguration, DecryptedMessage,
MemberAddedMessages, MlsCredentialType, ProposalBundle, WelcomeBundle,
};

pub mod e2ei;
pub mod proteus;
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::context::CoreCryptoContext;
use crate::generic::CoreCryptoResult;
use crate::{CoreCryptoError, ProteusAutoPrekeyBundle};
use crate::proteus_impl;
use crate::{CoreCryptoError, ProteusAutoPrekeyBundle};

#[uniffi::export]
impl CoreCryptoContext {
Expand Down
4 changes: 2 additions & 2 deletions crypto-ffi/src/wasm/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::{
CoreCryptoError, CoreCryptoResult, CredentialType, CustomConfiguration, DecryptedMessage, FfiClientId,
MemberAddedMessages, ProposalBundle, WasmCryptoResult, WelcomeBundle,
};
use core_crypto::context::CentralContext;
use core_crypto::prelude::{
CiphersuiteName, ClientId, ClientIdentifier, ConversationId, KeyPackageIn, KeyPackageRef,
MlsConversationConfiguration, VerifiableGroupInfo,
Expand All @@ -16,7 +17,6 @@ use tls_codec::{Deserialize, Serialize};
use wasm_bindgen::prelude::wasm_bindgen;
use wasm_bindgen::JsValue;
use wasm_bindgen_futures::future_to_promise;
use core_crypto::context::CentralContext;

mod e2ei;
mod proteus;
Expand All @@ -25,7 +25,7 @@ mod proteus;
#[derive(Clone)]
pub struct CoreCryptoContext {
pub(crate) inner: Arc<CentralContext>,
pub(crate) proteus_last_error_code: Arc<async_lock::RwLock<u32>>
pub(crate) proteus_last_error_code: Arc<async_lock::RwLock<u32>>,
}

#[wasm_bindgen]
Expand Down
54 changes: 27 additions & 27 deletions crypto-ffi/src/wasm/context/proteus.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use crate::proteus_impl;
use crate::wasm::context::CoreCryptoContext;
use crate::wasm::CoreCryptoError;
use crate::WasmError;
use crate::{ProteusAutoPrekeyBundle, WasmCryptoResult};
use futures_util::TryFutureExt;
use js_sys::{Promise, Uint8Array};
use wasm_bindgen::JsValue;
use wasm_bindgen::prelude::wasm_bindgen;
use wasm_bindgen::JsValue;
use wasm_bindgen_futures::future_to_promise;
use crate::wasm::context::CoreCryptoContext;
use crate::{ProteusAutoPrekeyBundle, WasmCryptoResult};
use crate::WasmError;
use crate::proteus_impl;
use crate::wasm::CoreCryptoError;

#[wasm_bindgen]
impl CoreCryptoContext {
Expand All @@ -25,10 +25,10 @@ impl CoreCryptoContext {
WasmCryptoResult::Ok(JsValue::UNDEFINED)
} or throw WasmCryptoResult<_> }
}
.err_into(),
.err_into(),
)
}

/// Returns: [`WasmCryptoResult<Vec<u8>>`]
///
/// See [core_crypto::context::CentralContext::proteus_session_from_message]
Expand All @@ -43,14 +43,14 @@ impl CoreCryptoContext {
WasmCryptoResult::Ok(Uint8Array::from(payload.as_slice()).into())
} or throw WasmCryptoResult<_> }
}
.err_into(),
.err_into(),
)
}

/// Returns: [`WasmCryptoResult<()>`]
///
///
/// /// **Note**: This isn't usually needed as persisting sessions happens automatically when decrypting/encrypting messages and initializing Sessions
///
///
/// See [core_crypto::context::CentralContext::proteus_session_save]
pub fn proteus_session_save(&self, session_id: String) -> Promise {
let errcode_dest = self.proteus_last_error_code.clone();
Expand All @@ -63,10 +63,10 @@ impl CoreCryptoContext {
WasmCryptoResult::Ok(JsValue::UNDEFINED)
} or throw WasmCryptoResult<_> }
}
.err_into(),
.err_into(),
)
}

/// Returns: [`WasmCryptoResult<()>`]
///
/// See [core_crypto::context::CentralContext::proteus_session_delete]
Expand All @@ -81,10 +81,10 @@ impl CoreCryptoContext {
WasmCryptoResult::Ok(JsValue::UNDEFINED)
} or throw WasmCryptoResult<_> }
}
.err_into(),
.err_into(),
)
}

/// Returns: [`WasmCryptoResult<bool>`]
///
/// See [core_crypto::context::CentralContext::proteus_session_exists]
Expand All @@ -99,12 +99,12 @@ impl CoreCryptoContext {
WasmCryptoResult::Ok(JsValue::from_bool(exists))
} or throw WasmCryptoResult<_> }
}
.err_into(),
.err_into(),
)
}

/// Returns: [`WasmCryptoResult<Vec<u8>>`]
///
///
/// See [core_crypto::context::CentralContext::proteus_decrypt]
pub fn proteus_decrypt(&self, session_id: String, ciphertext: Box<[u8]>) -> Promise {
let errcode_dest = self.proteus_last_error_code.clone();
Expand Down Expand Up @@ -166,20 +166,20 @@ impl CoreCryptoContext {
pub fn proteus_new_prekey(&self, prekey_id: u16) -> Promise {
let errcode_dest = self.proteus_last_error_code.clone();
let context = self.inner.clone();

future_to_promise(
async move {
proteus_impl! { errcode_dest => {
let prekey_raw = context.proteus_new_prekey(prekey_id).await.map_err(CoreCryptoError::from)?;
WasmCryptoResult::Ok(Uint8Array::from(prekey_raw.as_slice()).into())
} or throw WasmCryptoResult<_> }
}
.err_into(),
.err_into(),
)
}

/// Returns: [`WasmCryptoResult<ProteusAutoPrekeyBundle>`]
///
///
/// See [core_crypto::context::CentralContext::proteus_new_prekey_auto]
pub fn proteus_new_prekey_auto(&self) -> Promise {
let errcode_dest = self.proteus_last_error_code.clone();
Expand All @@ -191,12 +191,12 @@ impl CoreCryptoContext {
WasmCryptoResult::Ok(ProteusAutoPrekeyBundle { id, pkb }.into())
} or throw WasmCryptoResult<_> }
}
.err_into(),
.err_into(),
)
}

/// Returns [`WasmCryptoResult<Uint8Array>`]
///
///
/// See [core_crypto::context::CentralContext::proteus_last_resort_prekey]
pub fn proteus_last_resort_prekey(&self) -> Promise {
let errcode_dest = self.proteus_last_error_code.clone();
Expand Down Expand Up @@ -283,12 +283,12 @@ impl CoreCryptoContext {
WasmCryptoResult::Ok(JsValue::UNDEFINED)
} or throw WasmCryptoResult<_> }
}
.err_into(),
.err_into(),
)
}

/// Returns: [`WasmCryptoResult<u32>`]
///
///
/// NOTE: This will clear the last error code.
pub fn proteus_last_error_code(&self) -> Promise {
let errcode = self.proteus_last_error_code.clone();
Expand All @@ -302,7 +302,7 @@ impl CoreCryptoContext {
WasmCryptoResult::Ok(prev_value.into())
} or throw WasmCryptoResult<_> }
}
.err_into(),
.err_into(),
)
}
}
}
2 changes: 1 addition & 1 deletion crypto-ffi/src/wasm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ mod utils;
use std::collections::HashMap;
use std::ops::Deref;

use crate::proteus_impl;
use core_crypto::prelude::*;
use core_crypto::CryptoError;
use futures_util::future::TryFutureExt;
Expand All @@ -34,7 +35,6 @@ use utils::*;
use wasm_bindgen::prelude::*;
use wasm_bindgen::JsCast;
use wasm_bindgen_futures::future_to_promise;
use crate::proteus_impl;

#[allow(dead_code)]
pub(super) const VERSION: &str = env!("CARGO_PKG_VERSION");
Expand Down
12 changes: 8 additions & 4 deletions crypto/src/context.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
//! This module contains the primitives to enable transactional support on a higher level within the
//! [MlsCentral]. All mutating operations need to be done through a [CentralContext].

use std::{ops::Deref, sync::Arc};
use async_lock::{Mutex, RwLock, RwLockReadGuardArc, RwLockWriteGuardArc};
use mls_crypto_provider::{CryptoKeystore, TransactionalCryptoProvider};
use std::{ops::Deref, sync::Arc};

use crate::mls::MlsCentral;
use crate::{group_store::GroupStore, prelude::{Client, MlsConversation}, CoreCrypto, CoreCryptoCallbacks, CryptoError, CryptoResult};
use crate::proteus::ProteusCentral;

Check failure on line 9 in crypto/src/context.rs

View workflow job for this annotation

GitHub Actions / hack

unresolved import `crate::proteus`
use crate::{
group_store::GroupStore,
prelude::{Client, MlsConversation},
CoreCrypto, CoreCryptoCallbacks, CryptoError, CryptoResult,
};

/// This struct provides transactional support for Core Crypto.
///
Expand Down Expand Up @@ -57,7 +61,7 @@ impl CentralContext {
callbacks,
provider: mls_central.mls_backend.clone(),
mls_groups,
proteus_central
proteus_central,
}
.into(),
),
Expand Down Expand Up @@ -122,7 +126,7 @@ impl CentralContext {
ContextState::Invalid => Err(CryptoError::InvalidContext),
}
}

pub(crate) async fn proteus_central(&self) -> CryptoResult<Arc<Mutex<Option<ProteusCentral>>>> {
match self.state.read().await.deref() {
ContextState::Valid { proteus_central, .. } => Ok(proteus_central.clone()),
Expand Down
Loading

0 comments on commit 77ca951

Please sign in to comment.