wacore/libsignal/store/
mod.rs

1pub mod record_helpers;
2pub mod sender_key_name;
3
4use crate::libsignal::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#[async_trait]
12pub trait PreKeyStore: Send + Sync {
13    async fn load_prekey(
14        &self,
15        prekey_id: u32,
16    ) -> Result<Option<PreKeyRecordStructure>, StoreError>;
17    async fn store_prekey(
18        &self,
19        prekey_id: u32,
20        record: PreKeyRecordStructure,
21        uploaded: bool,
22    ) -> Result<(), StoreError>;
23    async fn contains_prekey(&self, prekey_id: u32) -> Result<bool, StoreError>;
24    async fn remove_prekey(&self, prekey_id: u32) -> Result<(), StoreError>;
25}
26
27#[async_trait]
28pub trait SignedPreKeyStore: Send + Sync {
29    async fn load_signed_prekey(
30        &self,
31        signed_prekey_id: u32,
32    ) -> Result<Option<SignedPreKeyRecordStructure>, StoreError>;
33    async fn load_signed_prekeys(&self) -> Result<Vec<SignedPreKeyRecordStructure>, StoreError>;
34    async fn store_signed_prekey(
35        &self,
36        signed_prekey_id: u32,
37        record: SignedPreKeyRecordStructure,
38    ) -> Result<(), StoreError>;
39    async fn contains_signed_prekey(&self, signed_prekey_id: u32) -> Result<bool, StoreError>;
40    async fn remove_signed_prekey(&self, signed_prekey_id: u32) -> Result<(), StoreError>;
41}
42
43#[async_trait]
44pub trait SessionStore: Send + Sync {
45    async fn load_session(&self, address: &ProtocolAddress) -> Result<SessionRecord, StoreError>;
46    async fn get_sub_device_sessions(&self, name: &str) -> Result<Vec<u32>, StoreError>;
47    async fn store_session(
48        &self,
49        address: &ProtocolAddress,
50        record: &SessionRecord,
51    ) -> Result<(), StoreError>;
52    async fn contains_session(&self, address: &ProtocolAddress) -> Result<bool, StoreError>;
53    async fn delete_session(&self, address: &ProtocolAddress) -> Result<(), StoreError>;
54    async fn delete_all_sessions(&self, name: &str) -> Result<(), StoreError>;
55}
56
57pub trait SignalProtocolStore:
58    IdentityKeyStore + PreKeyStore + SignedPreKeyStore + SessionStore
59{
60}
61
62impl<T: IdentityKeyStore + PreKeyStore + SignedPreKeyStore + SessionStore> SignalProtocolStore
63    for T
64{
65}