wacore_libsignal/store/
mod.rs1pub mod record_helpers;
2pub mod sender_key_name;
3
4use crate::protocol::{IdentityKeyStore, ProtocolAddress, SessionRecord};
5use async_trait::async_trait;
6use std::error::Error;
7use waproto::whatsapp::{PreKeyRecordStructure, SignedPreKeyRecordStructure};
8
9type StoreError = Box<dyn Error + Send + Sync>;
10
11#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
12#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
13pub trait PreKeyStore: Send + Sync {
14 async fn load_prekey(
15 &self,
16 prekey_id: u32,
17 ) -> Result<Option<PreKeyRecordStructure>, StoreError>;
18 async fn store_prekey(
19 &self,
20 prekey_id: u32,
21 record: PreKeyRecordStructure,
22 uploaded: bool,
23 ) -> Result<(), StoreError>;
24 async fn contains_prekey(&self, prekey_id: u32) -> Result<bool, StoreError>;
25 async fn remove_prekey(&self, prekey_id: u32) -> Result<(), StoreError>;
26}
27
28#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
29#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
30pub trait SignedPreKeyStore: Send + Sync {
31 async fn load_signed_prekey(
32 &self,
33 signed_prekey_id: u32,
34 ) -> Result<Option<SignedPreKeyRecordStructure>, StoreError>;
35 async fn load_signed_prekeys(&self) -> Result<Vec<SignedPreKeyRecordStructure>, StoreError>;
36 async fn store_signed_prekey(
37 &self,
38 signed_prekey_id: u32,
39 record: SignedPreKeyRecordStructure,
40 ) -> Result<(), StoreError>;
41 async fn contains_signed_prekey(&self, signed_prekey_id: u32) -> Result<bool, StoreError>;
42 async fn remove_signed_prekey(&self, signed_prekey_id: u32) -> Result<(), StoreError>;
43}
44
45#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
46#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
47pub trait SessionStore: Send + Sync {
48 async fn load_session(&self, address: &ProtocolAddress) -> Result<SessionRecord, StoreError>;
49 async fn get_sub_device_sessions(&self, name: &str) -> Result<Vec<u32>, StoreError>;
50 async fn store_session(
51 &self,
52 address: &ProtocolAddress,
53 record: &SessionRecord,
54 ) -> Result<(), StoreError>;
55 async fn contains_session(&self, address: &ProtocolAddress) -> Result<bool, StoreError>;
56 async fn delete_session(&self, address: &ProtocolAddress) -> Result<(), StoreError>;
57 async fn delete_all_sessions(&self, name: &str) -> Result<(), StoreError>;
58}
59
60pub trait SignalProtocolStore:
61 IdentityKeyStore + PreKeyStore + SignedPreKeyStore + SessionStore
62{
63}
64
65impl<T: IdentityKeyStore + PreKeyStore + SignedPreKeyStore + SessionStore> SignalProtocolStore
66 for T
67{
68}