1#![doc = include_str!("../../README.md")]
23#![cfg_attr(not(test), deny(missing_docs))]
24#![allow(clippy::single_component_path_imports)]
25
26use async_lock::Mutex;
27#[cfg(test)]
28pub use core_crypto_macros::{dispotent, durable, idempotent};
29use std::sync::Arc;
30
31pub use self::error::*;
32
33#[cfg(test)]
34#[macro_use]
35pub mod test_utils;
36mod error;
39
40pub mod mls;
42
43pub mod e2e_identity;
45
46#[cfg(feature = "proteus")]
47pub mod proteus;
49
50pub mod context;
51mod group_store;
52mod obfuscate;
53
54mod build_metadata;
55use crate::prelude::MlsCommitBundle;
56pub use build_metadata::{BUILD_METADATA, BuildMetadata};
57
58pub mod prelude {
60    pub use openmls::{
61        group::{MlsGroup, MlsGroupConfig},
62        prelude::{
63            Ciphersuite as CiphersuiteName, Credential, GroupEpoch, KeyPackage, KeyPackageIn, KeyPackageRef,
64            MlsMessageIn, Node, group_info::VerifiableGroupInfo,
65        },
66    };
67
68    pub use mls_crypto_provider::{EntropySeed, MlsCryptoProvider, RawEntropySeed};
69
70    pub use crate::{
71        CoreCrypto, MlsTransport,
72        e2e_identity::{
73            E2eiEnrollment,
74            conversation_state::E2eiConversationState,
75            device_status::DeviceStatus,
76            identity::{WireIdentity, X509Identity},
77            types::{E2eiAcmeChallenge, E2eiAcmeDirectory, E2eiNewAcmeAuthz, E2eiNewAcmeOrder},
78        },
79        error::{CryptoboxMigrationError, Error, KeystoreError, LeafError, MlsError, ProteusError, RecursiveError},
80        mls::{
81            MlsCentral,
82            ciphersuite::MlsCiphersuite,
83            client::id::ClientId,
84            client::identifier::ClientIdentifier,
85            client::key_package::INITIAL_KEYING_MATERIAL_COUNT,
86            client::*,
87            config::MlsCentralConfiguration,
88            conversation::{
89                ConversationId, MlsConversation,
90                commit::{MlsCommitBundle, MlsConversationCreationMessage},
91                config::{MlsConversationConfiguration, MlsCustomConfiguration, MlsWirePolicy},
92                conversation_guard::decrypt::{MlsBufferedConversationDecryptMessage, MlsConversationDecryptMessage},
93                group_info::{GroupInfoPayload, MlsGroupInfoBundle, MlsGroupInfoEncryptionType, MlsRatchetTreeType},
94                proposal::MlsProposalBundle,
95                welcome::WelcomeBundle,
96            },
97            credential::{typ::MlsCredentialType, x509::CertificateBundle},
98            proposal::{MlsProposal, MlsProposalRef},
99        },
100        obfuscate::Obfuscated,
101    };
102}
103
104pub enum MlsTransportResponse {
106    Success,
108    Retry,
110    Abort {
112        reason: String,
114    },
115}
116
117#[cfg_attr(target_family = "wasm", async_trait::async_trait(?Send))]
120#[cfg_attr(not(target_family = "wasm"), async_trait::async_trait)]
121pub trait MlsTransport: std::fmt::Debug + Send + Sync {
122    async fn send_commit_bundle(&self, commit_bundle: MlsCommitBundle) -> Result<MlsTransportResponse>;
124    async fn send_message(&self, mls_message: Vec<u8>) -> Result<MlsTransportResponse>;
126}
127
128#[derive(Debug)]
129pub struct CoreCrypto {
133    mls: mls::MlsCentral,
134    #[cfg(feature = "proteus")]
135    proteus: Arc<Mutex<Option<proteus::ProteusCentral>>>,
136    #[cfg(not(feature = "proteus"))]
137    #[allow(dead_code)]
138    proteus: (),
139}
140
141impl From<mls::MlsCentral> for CoreCrypto {
142    fn from(mls: mls::MlsCentral) -> Self {
143        Self {
144            mls,
145            proteus: Default::default(),
146        }
147    }
148}
149
150impl std::ops::Deref for CoreCrypto {
151    type Target = mls::MlsCentral;
152
153    fn deref(&self) -> &Self::Target {
154        &self.mls
155    }
156}
157
158impl std::ops::DerefMut for CoreCrypto {
159    fn deref_mut(&mut self) -> &mut Self::Target {
160        &mut self.mls
161    }
162}
163
164impl CoreCrypto {
165    #[inline]
167    pub fn take(self) -> mls::MlsCentral {
168        self.mls
169    }
170}