1#![doc = include_str!(env!("STRIPPED_README_PATH"))]
7#![cfg_attr(not(test), deny(missing_docs))]
8#![allow(clippy::single_component_path_imports)]
9
10#[cfg(test)]
11#[macro_use]
12pub mod test_utils;
13mod build_metadata;
16mod ephemeral;
17mod error;
18mod group_store;
19
20pub mod e2e_identity;
22pub mod mls;
24#[cfg(feature = "proteus")]
26pub mod proteus;
27pub mod transaction_context;
28
29pub use core_crypto_keystore::{ConnectionType, Database, DatabaseKey};
30#[cfg(test)]
31pub use core_crypto_macros::{dispotent, durable, idempotent};
32pub use mls_crypto_provider::{EntropySeed, MlsCryptoProvider, RawEntropySeed};
33pub use openmls::{
34 group::{MlsGroup, MlsGroupConfig},
35 prelude::{
36 Ciphersuite as MlsCiphersuite, GroupEpoch, KeyPackage, KeyPackageIn, KeyPackageRef, MlsMessageIn, Node,
37 group_info::VerifiableGroupInfo,
38 },
39};
40#[cfg(feature = "proteus")]
41use {async_lock::Mutex, std::sync::Arc};
42
43pub use crate::{
44 build_metadata::{BUILD_METADATA, BuildMetadata},
45 e2e_identity::{
46 E2eiEnrollment,
47 device_status::DeviceStatus,
48 identity::{WireIdentity, X509Identity},
49 types::{E2eiAcmeChallenge, E2eiAcmeDirectory, E2eiNewAcmeAuthz, E2eiNewAcmeOrder},
50 },
51 ephemeral::{HISTORY_CLIENT_ID_PREFIX, HistorySecret},
52 error::{
53 Error, InnermostErrorMessage, KeystoreError, LeafError, MlsError, MlsErrorKind, ProteusError, ProteusErrorKind,
54 RecursiveError, Result, ToRecursiveError,
55 },
56 mls::{
57 ciphersuite::Ciphersuite,
58 conversation::{
59 ConversationId, MlsConversation,
60 commit::MlsCommitBundle,
61 config::{MlsConversationConfiguration, MlsCustomConfiguration, MlsWirePolicy},
62 conversation_guard::decrypt::{MlsBufferedConversationDecryptMessage, MlsConversationDecryptMessage},
63 group_info::{GroupInfoPayload, MlsGroupInfoBundle, MlsGroupInfoEncryptionType, MlsRatchetTreeType},
64 proposal::MlsProposalBundle,
65 welcome::WelcomeBundle,
66 },
67 credential::{
68 Credential, CredentialRef, CredentialType, FindFilters as CredentialFindFilters, x509::CertificateBundle,
69 },
70 proposal::{MlsProposal, MlsProposalRef},
71 session::{
72 EpochObserver, HistoryObserver, Session,
73 id::{ClientId, ClientIdRef},
74 identifier::ClientIdentifier,
75 key_package::INITIAL_KEYING_MATERIAL_COUNT,
76 user_id::UserId,
77 },
78 },
79 transaction_context::e2e_identity::conversation_state::E2eiConversationState,
80};
81
82pub enum MlsTransportResponse {
84 Success,
86 Retry,
88 Abort {
90 reason: String,
92 },
93}
94
95#[derive(Debug, derive_more::From, derive_more::Deref, serde::Serialize, serde::Deserialize)]
98pub struct MlsTransportData(pub Vec<u8>);
99
100#[cfg_attr(target_family = "wasm", async_trait::async_trait(?Send))]
103#[cfg_attr(not(target_family = "wasm"), async_trait::async_trait)]
104pub trait MlsTransport: std::fmt::Debug + Send + Sync {
105 async fn send_commit_bundle(&self, commit_bundle: MlsCommitBundle) -> Result<MlsTransportResponse>;
107 async fn send_message(&self, mls_message: Vec<u8>) -> Result<MlsTransportResponse>;
109
110 async fn prepare_for_transport(&self, secret: &HistorySecret) -> Result<MlsTransportData>;
117}
118
119#[derive(Debug, Clone)]
126pub struct CoreCrypto {
127 mls: mls::session::Session,
128 #[cfg(feature = "proteus")]
129 proteus: Arc<Mutex<Option<proteus::ProteusCentral>>>,
130 #[cfg(not(feature = "proteus"))]
131 #[allow(dead_code)]
132 proteus: (),
133}
134
135impl From<mls::session::Session> for CoreCrypto {
136 fn from(mls: mls::session::Session) -> Self {
137 Self {
138 mls,
139 proteus: Default::default(),
140 }
141 }
142}
143
144impl std::ops::Deref for CoreCrypto {
145 type Target = mls::session::Session;
146
147 fn deref(&self) -> &Self::Target {
148 &self.mls
149 }
150}
151
152impl std::ops::DerefMut for CoreCrypto {
153 fn deref_mut(&mut self) -> &mut Self::Target {
154 &mut self.mls
155 }
156}
157
158impl CoreCrypto {
159 #[inline]
161 pub fn take(self) -> mls::session::Session {
162 self.mls
163 }
164}