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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
use crate::{AccountCache, CertCache};
use async_trait::async_trait;
use std::convert::Infallible;
use std::fmt::Debug;
use std::marker::PhantomData;
use std::sync::atomic::AtomicPtr;

/// No-op cache, which does nothing.
/// ```rust
/// # use tokio_rustls_acme::caches::NoCache;
/// # type EC = std::io::Error;
/// # type EA = EC;
/// let no_cache = NoCache::<EC, EA>::new();
/// ```
#[derive(Copy, Clone)]
pub struct NoCache<EC: Debug = Infallible, EA: Debug = Infallible> {
    _cert_error: PhantomData<AtomicPtr<Box<EC>>>,
    _account_error: PhantomData<AtomicPtr<Box<EA>>>,
}

impl<EC: Debug, EA: Debug> Default for NoCache<EC, EA> {
    fn default() -> Self {
        Self {
            _cert_error: Default::default(),
            _account_error: Default::default(),
        }
    }
}

impl<EC: Debug, EA: Debug> NoCache<EC, EA> {
    pub fn new() -> Self {
        Self::default()
    }
}

#[async_trait]
impl<EC: Debug, EA: Debug> CertCache for NoCache<EC, EA> {
    type EC = EC;
    async fn load_cert(
        &self,
        _domains: &[String],
        _directory_url: &str,
    ) -> Result<Option<Vec<u8>>, Self::EC> {
        log::info!("no cert cache configured, could not load certificate");
        Ok(None)
    }
    async fn store_cert(
        &self,
        _domains: &[String],
        _directory_url: &str,
        _cert: &[u8],
    ) -> Result<(), Self::EC> {
        log::info!("no cert cache configured, could not store certificate");
        Ok(())
    }
}

#[async_trait]
impl<EC: Debug, EA: Debug> AccountCache for NoCache<EC, EA> {
    type EA = EA;
    async fn load_account(
        &self,
        _contact: &[String],
        _directory_url: &str,
    ) -> Result<Option<Vec<u8>>, Self::EA> {
        log::info!("no account cache configured, could not load account");
        Ok(None)
    }
    async fn store_account(
        &self,
        _contact: &[String],
        _directory_url: &str,
        _account: &[u8],
    ) -> Result<(), Self::EA> {
        log::info!("no account cache configured, could not store account");
        Ok(())
    }
}