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