Skip to main content

core_crypto_keystore/transaction/
proteus.rs

1use crate::{
2    CryptoKeystoreError, Transaction,
3    entities::ProteusPrekey,
4    traits::{EntityDatabaseMutation as _, FetchFromDatabase},
5};
6
7#[cfg_attr(target_os = "unknown", async_trait::async_trait(?Send))]
8#[cfg_attr(not(target_os = "unknown"), async_trait::async_trait)]
9impl proteus_traits::PreKeyStore for Transaction {
10    type Error = CryptoKeystoreError;
11
12    async fn prekey(&self, id: proteus_traits::RawPreKeyId) -> Result<Option<proteus_traits::RawPreKey>, Self::Error> {
13        FetchFromDatabase::get::<ProteusPrekey>(self, &id)
14            .await
15            .map(|maybe_prekey| maybe_prekey.map(|db_prekey| db_prekey.prekey.clone()))
16    }
17
18    async fn remove(&self, id: proteus_traits::RawPreKeyId) -> Result<(), Self::Error> {
19        ProteusPrekey::delete(self, &id)?;
20        Ok(())
21    }
22}