core_crypto_ffi/core_crypto_context/
mod.rs1#[cfg(target_family = "wasm")]
2pub(crate) mod array_of_byte_array;
3mod e2ei;
4mod mls;
5mod proteus;
6
7use std::{ops::Deref, sync::Arc};
8
9#[cfg(target_family = "wasm")]
10use wasm_bindgen::prelude::*;
11
12use core_crypto::transaction_context::TransactionContext;
13
14use crate::CoreCryptoResult;
15
16#[derive(Debug)]
17#[cfg_attr(target_family = "wasm", wasm_bindgen)]
18#[cfg_attr(not(target_family = "wasm"), derive(uniffi::Object))]
19pub struct CoreCryptoContext {
20 pub(crate) inner: Arc<TransactionContext>,
21}
22
23impl Deref for CoreCryptoContext {
24 type Target = TransactionContext;
25
26 fn deref(&self) -> &Self::Target {
27 self.inner.deref()
28 }
29}
30
31#[cfg_attr(target_family = "wasm", wasm_bindgen)]
32#[cfg_attr(not(target_family = "wasm"), uniffi::export)]
33impl CoreCryptoContext {
34 pub async fn set_data(&self, data: Vec<u8>) -> CoreCryptoResult<()> {
36 self.inner.set_data(data).await.map_err(Into::into)
37 }
38
39 pub async fn get_data(&self) -> CoreCryptoResult<Option<Vec<u8>>> {
41 self.inner.get_data().await.map_err(Into::into)
42 }
43
44 pub async fn random_bytes(&self, len: u32) -> CoreCryptoResult<Vec<u8>> {
46 self.inner.random_bytes(len as _).await.map_err(Into::into)
47 }
48}