core_crypto_ffi/generic/context/
proteus.rs1use crate::ProteusAutoPrekeyBundle;
2use crate::context::CoreCryptoContext;
3use crate::generic::CoreCryptoResult;
4use crate::proteus_impl;
5
6#[uniffi::export]
7impl CoreCryptoContext {
8 pub async fn proteus_init(&self) -> CoreCryptoResult<()> {
10 proteus_impl!({
11 self.context.proteus_init().await?;
12 Ok(())
13 })
14 }
15
16 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 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 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 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 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 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 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 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 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 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 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 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 pub async fn proteus_fingerprint(&self) -> CoreCryptoResult<String> {
99 proteus_impl!({ Ok(self.context.proteus_fingerprint().await?) })
100 }
101
102 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 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 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 pub async fn proteus_cryptobox_migrate(&self, path: String) -> CoreCryptoResult<()> {
120 proteus_impl!({ Ok(self.context.proteus_cryptobox_migrate(&path).await?) })
121 }
122
123 pub async fn proteus_reload_sessions(&self) -> CoreCryptoResult<()> {
125 proteus_impl!({ Ok(self.context.proteus_reload_sessions().await?) })
126 }
127}