core_crypto_ffi/generic/context/
proteus.rs

1use crate::ProteusAutoPrekeyBundle;
2use crate::context::CoreCryptoContext;
3use crate::generic::CoreCryptoResult;
4use crate::proteus_impl;
5
6#[uniffi::export]
7impl CoreCryptoContext {
8    /// See [core_crypto::proteus::ProteusCentral::try_new]
9    pub async fn proteus_init(&self) -> CoreCryptoResult<()> {
10        proteus_impl!({
11            self.context.proteus_init().await?;
12            Ok(())
13        })
14    }
15
16    /// See [core_crypto::context::CentralContext::proteus_session_from_prekey]
17    pub async fn proteus_session_from_prekey(&self, session_id: String, prekey: Vec<u8>) -> CoreCryptoResult<()> {
18        proteus_impl!({
19            self.context.proteus_session_from_prekey(&session_id, &prekey).await?;
20            Ok(())
21        })
22    }
23
24    /// See [core_crypto::context::CentralContext::proteus_session_from_message]
25    pub async fn proteus_session_from_message(
26        &self,
27        session_id: String,
28        envelope: Vec<u8>,
29    ) -> CoreCryptoResult<Vec<u8>> {
30        proteus_impl!({
31            let (_, payload) = self
32                .context
33                .proteus_session_from_message(&session_id, &envelope)
34                .await?;
35            Ok(payload)
36        })
37    }
38
39    /// See [core_crypto::context::CentralContext::proteus_session_save]
40    /// **Note**: This isn't usually needed as persisting sessions happens automatically when decrypting/encrypting messages and initializing Sessions
41    pub async fn proteus_session_save(&self, session_id: String) -> CoreCryptoResult<()> {
42        proteus_impl!({ Ok(self.context.proteus_session_save(&session_id).await?) })
43    }
44
45    /// See [core_crypto::context::CentralContext::proteus_session_delete]
46    pub async fn proteus_session_delete(&self, session_id: String) -> CoreCryptoResult<()> {
47        proteus_impl!({ Ok(self.context.proteus_session_delete(&session_id).await?) })
48    }
49
50    /// See [core_crypto::context::CentralContext::proteus_session_exists]
51    pub async fn proteus_session_exists(&self, session_id: String) -> CoreCryptoResult<bool> {
52        proteus_impl!({ Ok(self.context.proteus_session_exists(&session_id).await?) })
53    }
54
55    /// See [core_crypto::context::CentralContext::proteus_decrypt]
56    pub async fn proteus_decrypt(&self, session_id: String, ciphertext: Vec<u8>) -> CoreCryptoResult<Vec<u8>> {
57        proteus_impl!({ Ok(self.context.proteus_decrypt(&session_id, &ciphertext).await?) })
58    }
59
60    /// See [core_crypto::context::CentralContext::proteus_encrypt]
61    pub async fn proteus_encrypt(&self, session_id: String, plaintext: Vec<u8>) -> CoreCryptoResult<Vec<u8>> {
62        proteus_impl!({ Ok(self.context.proteus_encrypt(&session_id, &plaintext).await?) })
63    }
64
65    /// See [core_crypto::context::CentralContext::proteus_encrypt_batched]
66    pub async fn proteus_encrypt_batched(
67        &self,
68        sessions: Vec<String>,
69        plaintext: Vec<u8>,
70    ) -> CoreCryptoResult<std::collections::HashMap<String, Vec<u8>>> {
71        proteus_impl!({ Ok(self.context.proteus_encrypt_batched(&sessions, &plaintext).await?) })
72    }
73
74    /// See [core_crypto::context::CentralContext::proteus_new_prekey]
75    pub async fn proteus_new_prekey(&self, prekey_id: u16) -> CoreCryptoResult<Vec<u8>> {
76        proteus_impl!({ CoreCryptoResult::Ok(self.context.proteus_new_prekey(prekey_id).await?) })
77    }
78
79    /// See [core_crypto::context::CentralContext::proteus_new_prekey_auto]
80    pub async fn proteus_new_prekey_auto(&self) -> CoreCryptoResult<ProteusAutoPrekeyBundle> {
81        proteus_impl!({
82            let (id, pkb) = self.context.proteus_new_prekey_auto().await?;
83            CoreCryptoResult::Ok(ProteusAutoPrekeyBundle { id, pkb })
84        })
85    }
86
87    /// See [core_crypto::context::CentralContext::proteus_last_resort_prekey]
88    pub async fn proteus_last_resort_prekey(&self) -> CoreCryptoResult<Vec<u8>> {
89        proteus_impl!({ Ok(self.context.proteus_last_resort_prekey().await?) })
90    }
91
92    /// See [core_crypto::context::CentralContext::proteus_last_resort_prekey_id]
93    pub fn proteus_last_resort_prekey_id(&self) -> CoreCryptoResult<u16> {
94        proteus_impl!({ Ok(core_crypto::CoreCrypto::proteus_last_resort_prekey_id()) })
95    }
96
97    /// See [core_crypto::context::CentralContext::proteus_fingerprint]
98    pub async fn proteus_fingerprint(&self) -> CoreCryptoResult<String> {
99        proteus_impl!({ Ok(self.context.proteus_fingerprint().await?) })
100    }
101
102    /// See [core_crypto::context::CentralContext::proteus_fingerprint_local]
103    pub async fn proteus_fingerprint_local(&self, session_id: String) -> CoreCryptoResult<String> {
104        proteus_impl!({ Ok(self.context.proteus_fingerprint_local(&session_id).await?) })
105    }
106
107    /// See [core_crypto::context::CentralContext::proteus_fingerprint_remote]
108    pub async fn proteus_fingerprint_remote(&self, session_id: String) -> CoreCryptoResult<String> {
109        proteus_impl!({ Ok(self.context.proteus_fingerprint_remote(&session_id).await?) })
110    }
111
112    /// See [core_crypto::proteus::ProteusCentral::fingerprint_prekeybundle]
113    /// NOTE: uniffi doesn't support associated functions, so we have to have the self here
114    pub fn proteus_fingerprint_prekeybundle(&self, prekey: Vec<u8>) -> CoreCryptoResult<String> {
115        proteus_impl!({ Ok(core_crypto::proteus::ProteusCentral::fingerprint_prekeybundle(&prekey)?) })
116    }
117
118    /// See [core_crypto::context::CentralContext::proteus_cryptobox_migrate]
119    pub async fn proteus_cryptobox_migrate(&self, path: String) -> CoreCryptoResult<()> {
120        proteus_impl!({ Ok(self.context.proteus_cryptobox_migrate(&path).await?) })
121    }
122
123    /// See [core_crypto::context::CentralContext::proteus_reload_sessions]
124    pub async fn proteus_reload_sessions(&self) -> CoreCryptoResult<()> {
125        proteus_impl!({ Ok(self.context.proteus_reload_sessions().await?) })
126    }
127}