interop/clients/
mod.rs

1#![allow(clippy::assign_op_pattern)]
2
3use color_eyre::eyre::Result;
4use core_crypto::prelude::MlsCiphersuite;
5
6pub(crate) mod corecrypto;
7#[cfg(feature = "proteus")]
8pub(crate) mod cryptobox;
9
10bitflags::bitflags! {
11    pub(crate) struct EmulatedClientProtocol: u8 {
12        const MLS = 0x01;
13        const PROTEUS = 0x02;
14    }
15}
16
17#[derive(Debug)]
18#[non_exhaustive]
19#[allow(dead_code)]
20pub(crate) enum EmulatedClientType {
21    Native,
22    // Natively test the FFI in `generic.rs`
23    NativeFfi,
24    Web,
25    // TODO: Bind with & drive iOS Emulator. Tracking issue: WPB-9646
26    AppleiOS,
27    // TODO: Bind with & drive Android Emulator. Tracking issue: WPB-9646
28    Android,
29}
30
31impl std::fmt::Display for EmulatedClientType {
32    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
33        let repr = match self {
34            Self::Native => "Native",
35            Self::NativeFfi => "Native FFI",
36            Self::Web => "Web",
37            Self::AppleiOS => "iOS",
38            Self::Android => "Android",
39        };
40
41        write!(f, "{repr}")
42    }
43}
44
45#[async_trait::async_trait(?Send)]
46#[allow(dead_code)]
47pub(crate) trait EmulatedClient {
48    fn client_name(&self) -> &str;
49    fn client_type(&self) -> EmulatedClientType;
50    fn client_id(&self) -> &[u8];
51    fn client_protocol(&self) -> EmulatedClientProtocol;
52    async fn wipe(&mut self) -> Result<()>;
53}
54
55#[async_trait::async_trait(?Send)]
56#[allow(dead_code)]
57pub(crate) trait EmulatedMlsClient: EmulatedClient {
58    async fn get_keypackage(&self) -> Result<Vec<u8>>;
59    async fn add_client(&self, conversation_id: &[u8], kp: &[u8]) -> Result<()>;
60    async fn kick_client(&self, conversation_id: &[u8], client_id: &[u8]) -> Result<()>;
61    async fn process_welcome(&self, welcome: &[u8]) -> Result<Vec<u8>>;
62    async fn encrypt_message(&self, conversation_id: &[u8], message: &[u8]) -> Result<Vec<u8>>;
63    // TODO: Make it more complex so that we can extract other things like proposals etc. Tracking issue: WPB-9647
64    async fn decrypt_message(&self, conversation_id: &[u8], message: &[u8]) -> Result<Option<Vec<u8>>>;
65}
66
67#[async_trait::async_trait(?Send)]
68#[allow(dead_code)]
69pub(crate) trait EmulatedProteusClient: EmulatedClient {
70    async fn init(&mut self) -> Result<()> {
71        Ok(())
72    }
73    async fn get_prekey(&self) -> Result<Vec<u8>>;
74    async fn session_from_prekey(&self, session_id: &str, prekey: &[u8]) -> Result<()>;
75    async fn session_from_message(&self, session_id: &str, message: &[u8]) -> Result<Vec<u8>>;
76    async fn encrypt(&self, session_id: &str, plaintext: &[u8]) -> Result<Vec<u8>>;
77    async fn decrypt(&self, session_id: &str, ciphertext: &[u8]) -> Result<Vec<u8>>;
78    async fn fingerprint(&self) -> Result<String>;
79}
80
81#[async_trait::async_trait(?Send)]
82#[allow(dead_code)]
83pub(crate) trait EmulatedE2eIdentityClient: EmulatedClient {
84    async fn e2ei_new_enrollment(&mut self, ciphersuite: MlsCiphersuite) -> Result<()>;
85}