core_crypto_keystore/
proteus.rs1use crate::{
18 CryptoKeystoreError, CryptoKeystoreResult,
19 connection::{Connection, FetchFromDatabase},
20 entities::ProteusPrekey,
21};
22
23#[cfg_attr(target_family = "wasm", async_trait::async_trait(?Send))]
24#[cfg_attr(not(target_family = "wasm"), async_trait::async_trait)]
25pub trait CryptoKeystoreProteus {
26 async fn proteus_store_prekey(&self, id: u16, prekey: &[u8]) -> CryptoKeystoreResult<()>;
27}
28
29#[cfg_attr(target_family = "wasm", async_trait::async_trait(?Send))]
30#[cfg_attr(not(target_family = "wasm"), async_trait::async_trait)]
31impl CryptoKeystoreProteus for Connection {
32 async fn proteus_store_prekey(&self, id: u16, prekey: &[u8]) -> CryptoKeystoreResult<()> {
33 let entity = ProteusPrekey::from_raw(id, prekey.to_vec());
34 self.save(entity).await?;
35 Ok(())
36 }
37}
38
39#[cfg_attr(target_family = "wasm", async_trait::async_trait(?Send))]
40#[cfg_attr(not(target_family = "wasm"), async_trait::async_trait)]
41impl proteus_traits::PreKeyStore for Connection {
42 type Error = CryptoKeystoreError;
43
44 async fn prekey(
45 &mut self,
46 id: proteus_traits::RawPreKeyId,
47 ) -> Result<Option<proteus_traits::RawPreKey>, Self::Error> {
48 Ok(self
49 .find::<ProteusPrekey>(&id.to_le_bytes())
50 .await?
51 .map(|db_prekey| db_prekey.prekey.clone()))
52 }
53
54 async fn remove(&mut self, id: proteus_traits::RawPreKeyId) -> Result<(), Self::Error> {
55 Connection::remove::<ProteusPrekey, _>(self, id.to_le_bytes()).await?;
56
57 Ok(())
58 }
59}