1#![allow(clippy::assign_op_pattern)]
17
18use color_eyre::eyre::Result;
19use core_crypto::prelude::MlsCiphersuite;
20
21pub(crate) mod corecrypto;
22#[cfg(feature = "proteus")]
23pub(crate) mod cryptobox;
24
25bitflags::bitflags! {
26 pub(crate) struct EmulatedClientProtocol: u8 {
27 const MLS = 0x01;
28 const PROTEUS = 0x02;
29 }
30}
31
32#[derive(Debug)]
33#[non_exhaustive]
34#[allow(dead_code)]
35pub(crate) enum EmulatedClientType {
36 Native,
37 NativeFfi,
39 Web,
40 AppleiOS,
42 Android,
44}
45
46impl std::fmt::Display for EmulatedClientType {
47 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
48 let repr = match self {
49 Self::Native => "Native",
50 Self::NativeFfi => "Native FFI",
51 Self::Web => "Web",
52 Self::AppleiOS => "iOS",
53 Self::Android => "Android",
54 };
55
56 write!(f, "{repr}")
57 }
58}
59
60#[async_trait::async_trait(?Send)]
61#[allow(dead_code)]
62pub(crate) trait EmulatedClient {
63 fn client_name(&self) -> &str;
64 fn client_type(&self) -> EmulatedClientType;
65 fn client_id(&self) -> &[u8];
66 fn client_protocol(&self) -> EmulatedClientProtocol;
67 async fn wipe(mut self) -> Result<()>;
68}
69
70#[async_trait::async_trait(?Send)]
71#[allow(dead_code)]
72pub(crate) trait EmulatedMlsClient: EmulatedClient {
73 async fn get_keypackage(&self) -> Result<Vec<u8>>;
74 async fn add_client(&self, conversation_id: &[u8], kp: &[u8]) -> Result<()>;
75 async fn kick_client(&self, conversation_id: &[u8], client_id: &[u8]) -> Result<()>;
76 async fn process_welcome(&self, welcome: &[u8]) -> Result<Vec<u8>>;
77 async fn encrypt_message(&self, conversation_id: &[u8], message: &[u8]) -> Result<Vec<u8>>;
78 async fn decrypt_message(&self, conversation_id: &[u8], message: &[u8]) -> Result<Option<Vec<u8>>>;
80}
81
82#[async_trait::async_trait(?Send)]
83#[allow(dead_code)]
84pub(crate) trait EmulatedProteusClient: EmulatedClient {
85 async fn init(&mut self) -> Result<()> {
86 Ok(())
87 }
88 async fn get_prekey(&self) -> Result<Vec<u8>>;
89 async fn session_from_prekey(&self, session_id: &str, prekey: &[u8]) -> Result<()>;
90 async fn session_from_message(&self, session_id: &str, message: &[u8]) -> Result<Vec<u8>>;
91 async fn encrypt(&self, session_id: &str, plaintext: &[u8]) -> Result<Vec<u8>>;
92 async fn decrypt(&self, session_id: &str, ciphertext: &[u8]) -> Result<Vec<u8>>;
93 async fn fingerprint(&self) -> Result<String>;
94}
95
96#[async_trait::async_trait(?Send)]
97#[allow(dead_code)]
98pub(crate) trait EmulatedE2eIdentityClient: EmulatedClient {
99 async fn e2ei_new_enrollment(&mut self, ciphersuite: MlsCiphersuite) -> Result<()>;
100}