tokio_rustls_acme/caches/
boxed.rs1use crate::{AccountCache, CertCache};
2use async_trait::async_trait;
3use std::fmt::Debug;
4
5pub struct BoxedErrCache<T: Send + Sync> {
6 inner: T,
7}
8
9impl<T: Send + Sync> BoxedErrCache<T> {
10 pub fn new(inner: T) -> Self {
11 Self { inner }
12 }
13 pub fn into_inner(self) -> T {
14 self.inner
15 }
16}
17
18fn box_err(e: impl Debug + 'static) -> Box<dyn Debug> {
19 Box::new(e)
20}
21
22#[async_trait]
23impl<T: CertCache> CertCache for BoxedErrCache<T>
24where
25 <T as CertCache>::EC: 'static,
26{
27 type EC = Box<dyn Debug>;
28 async fn load_cert(
29 &self,
30 domains: &[String],
31 directory_url: &str,
32 ) -> Result<Option<Vec<u8>>, Self::EC> {
33 self.inner
34 .load_cert(domains, directory_url)
35 .await
36 .map_err(box_err)
37 }
38
39 async fn store_cert(
40 &self,
41 domains: &[String],
42 directory_url: &str,
43 cert: &[u8],
44 ) -> Result<(), Self::EC> {
45 self.inner
46 .store_cert(domains, directory_url, cert)
47 .await
48 .map_err(box_err)
49 }
50}
51
52#[async_trait]
53impl<T: AccountCache> AccountCache for BoxedErrCache<T>
54where
55 <T as AccountCache>::EA: 'static,
56{
57 type EA = Box<dyn Debug>;
58 async fn load_account(
59 &self,
60 contact: &[String],
61 directory_url: &str,
62 ) -> Result<Option<Vec<u8>>, Self::EA> {
63 self.inner
64 .load_account(contact, directory_url)
65 .await
66 .map_err(box_err)
67 }
68
69 async fn store_account(
70 &self,
71 contact: &[String],
72 directory_url: &str,
73 account: &[u8],
74 ) -> Result<(), Self::EA> {
75 self.inner
76 .store_account(contact, directory_url, account)
77 .await
78 .map_err(box_err)
79 }
80}