1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
use crate::{error::SendSyncError, ErrorKind};
pub trait Vault: std::fmt::Debug + Send + Sync + 'static {
type Error: SendSyncError;
fn encrypt(&self, payload: &[u8]) -> Result<Vec<u8>, Self::Error>;
fn decrypt(&self, payload: &[u8]) -> Result<Vec<u8>, Self::Error>;
}
pub trait AnyVault: std::fmt::Debug + Send + Sync + 'static {
fn encrypt(&self, payload: &[u8]) -> Result<Vec<u8>, crate::Error>;
fn decrypt(&self, payload: &[u8]) -> Result<Vec<u8>, crate::Error>;
}
impl<T, E> AnyVault for T
where
T: Vault<Error = E> + std::fmt::Debug,
E: SendSyncError,
{
fn encrypt(&self, payload: &[u8]) -> Result<Vec<u8>, crate::Error> {
self.encrypt(payload)
.map_err(|err| crate::Error::from(ErrorKind::Vault(Box::new(err))))
}
fn decrypt(&self, payload: &[u8]) -> Result<Vec<u8>, crate::Error> {
Vault::decrypt(self, payload)
.map_err(|err| crate::Error::from(ErrorKind::Vault(Box::new(err))))
}
}