core_crypto_ffi/core_crypto/
proteus.rs

1#[cfg(target_family = "wasm")]
2use wasm_bindgen::prelude::*;
3
4use crate::{CoreCrypto, CoreCryptoResult, proteus_impl};
5
6#[cfg_attr(not(target_family = "wasm"), uniffi::export)]
7#[cfg_attr(target_family = "wasm", wasm_bindgen)]
8impl CoreCrypto {
9    /// See [core_crypto::proteus::ProteusCentral::session_exists]
10    pub async fn proteus_session_exists(&self, session_id: String) -> CoreCryptoResult<bool> {
11        proteus_impl!({ self.inner.proteus_session_exists(&session_id).await.map_err(Into::into) })
12    }
13
14    /// See [core_crypto::proteus::ProteusCentral::fingerprint]
15    pub async fn proteus_fingerprint(&self) -> CoreCryptoResult<String> {
16        proteus_impl!({ self.inner.proteus_fingerprint().await.map_err(Into::into) })
17    }
18
19    /// See [core_crypto::proteus::ProteusCentral::fingerprint_local]
20    pub async fn proteus_fingerprint_local(&self, session_id: String) -> CoreCryptoResult<String> {
21        proteus_impl!({
22            self.inner
23                .proteus_fingerprint_local(&session_id)
24                .await
25                .map_err(Into::into)
26        })
27    }
28
29    /// See [core_crypto::proteus::ProteusCentral::fingerprint_remote]
30    pub async fn proteus_fingerprint_remote(&self, session_id: String) -> CoreCryptoResult<String> {
31        proteus_impl!({
32            self.inner
33                .proteus_fingerprint_remote(&session_id)
34                .await
35                .map_err(Into::into)
36        })
37    }
38}
39
40// here are some static members, except that Uniffi doesn't do that, so we insert a pointless `self` param in that context
41
42/// See [core_crypto::proteus::ProteusCentral::last_resort_prekey_id]
43fn last_resort_prekey_id_inner() -> CoreCryptoResult<u16> {
44    proteus_impl!({ Ok(core_crypto::CoreCrypto::proteus_last_resort_prekey_id()) })
45}
46
47/// See [core_crypto::proteus::ProteusCentral::fingerprint_prekeybundle]
48fn fingerprint_prekeybundle_inner(prekey: Vec<u8>) -> CoreCryptoResult<String> {
49    proteus_impl!({ core_crypto::proteus::ProteusCentral::fingerprint_prekeybundle(&prekey).map_err(Into::into) })
50}
51
52#[cfg(target_family = "wasm")]
53#[wasm_bindgen]
54impl CoreCrypto {
55    /// See [core_crypto::proteus::ProteusCentral::last_resort_prekey_id]
56    pub fn proteus_last_resort_prekey_id() -> CoreCryptoResult<u16> {
57        last_resort_prekey_id_inner()
58    }
59
60    /// See [core_crypto::proteus::ProteusCentral::fingerprint_prekeybundle]
61    pub fn proteus_fingerprint_prekeybundle(prekey: Vec<u8>) -> CoreCryptoResult<String> {
62        fingerprint_prekeybundle_inner(prekey)
63    }
64}
65
66#[cfg(not(target_family = "wasm"))]
67#[uniffi::export]
68impl CoreCrypto {
69    /// See [core_crypto::proteus::ProteusCentral::last_resort_prekey_id]
70    pub fn proteus_last_resort_prekey_id(&self) -> CoreCryptoResult<u16> {
71        last_resort_prekey_id_inner()
72    }
73
74    /// See [core_crypto::proteus::ProteusCentral::fingerprint_prekeybundle]
75    pub fn proteus_fingerprint_prekeybundle(&self, prekey: Vec<u8>) -> CoreCryptoResult<String> {
76        fingerprint_prekeybundle_inner(prekey)
77    }
78}