bitwarden_ipc/traits/
crypto_provider.rs1use std::fmt::Debug;
2
3use super::{CommunicationBackend, CommunicationBackendReceiver, SessionRepository};
4use crate::message::{IncomingMessage, OutgoingMessage};
5
6pub trait CryptoProvider<Com, Ses>: Send + Sync + 'static
7where
8 Com: CommunicationBackend,
9 Ses: SessionRepository<Self::Session>,
10{
11 type Session: Send + Sync + 'static;
12 type SendError: Debug + Send + Sync + 'static;
13 type ReceiveError: Debug + Send + Sync + 'static;
14
15 fn send(
26 &self,
27 communication: &Com,
28 sessions: &Ses,
29 message: OutgoingMessage,
30 ) -> impl std::future::Future<Output = Result<(), Self::SendError>> + Send;
31
32 fn receive(
44 &self,
45 receiver: &Com::Receiver,
46 communication: &Com,
47 sessions: &Ses,
48 ) -> impl std::future::Future<Output = Result<IncomingMessage, Self::ReceiveError>> + Send + Sync;
49}
50
51pub struct NoEncryptionCryptoProvider;
52
53impl<Com, Ses> CryptoProvider<Com, Ses> for NoEncryptionCryptoProvider
54where
55 Com: CommunicationBackend,
56 Ses: SessionRepository<()>,
57{
58 type Session = ();
59 type SendError = Com::SendError;
60 type ReceiveError = <Com::Receiver as CommunicationBackendReceiver>::ReceiveError;
61
62 async fn send(
63 &self,
64 communication: &Com,
65 _sessions: &Ses,
66 message: OutgoingMessage,
67 ) -> Result<(), Self::SendError> {
68 communication.send(message).await
69 }
70
71 async fn receive(
72 &self,
73 receiver: &Com::Receiver,
74 _communication: &Com,
75 _sessions: &Ses,
76 ) -> Result<IncomingMessage, Self::ReceiveError> {
77 receiver.receive().await
78 }
79}