drogue_bazaar/core/tls/
auth.rs

1/// TLS client authentication mode.
2#[derive(Clone, Copy)]
3pub enum TlsMode {
4    /// No client authentication
5    NoClient,
6    /// with Drogue specific client authentication
7    Client,
8}
9
10/// TLS configuration
11pub struct TlsAuthConfig {
12    pub mode: TlsMode,
13    #[cfg(feature = "openssl")]
14    pub psk: Option<
15        Box<
16            dyn Fn(
17                    &mut openssl::ssl::SslRef,
18                    Option<&[u8]>,
19                    &mut [u8],
20                ) -> Result<usize, std::io::Error>
21                + Sync
22                + Send,
23        >,
24    >,
25}
26
27impl Default for TlsAuthConfig {
28    fn default() -> Self {
29        Self {
30            mode: TlsMode::NoClient,
31            #[cfg(feature = "openssl")]
32            psk: None,
33        }
34    }
35}
36
37/// Syntactic sugar for working with [`TlsAuthConfig`].
38pub trait WithTlsAuthConfig {
39    fn with_tls_auth_config(&self, tls_config: TlsAuthConfig) -> Option<TlsAuthConfig>;
40}
41
42/// Boolean flag means disable.
43impl WithTlsAuthConfig for bool {
44    fn with_tls_auth_config(&self, tls_config: TlsAuthConfig) -> Option<TlsAuthConfig> {
45        if *self {
46            None
47        } else {
48            Some(tls_config)
49        }
50    }
51}