1#![warn(missing_docs)]
3#![cfg_attr(docsrs, feature(doc_auto_cfg))]
4
5use crate::cache::SessionKey;
6use boring::error::ErrorStack;
7use boring::ex_data::Index;
8use boring::ssl::Ssl;
9use std::fmt;
10use std::sync::LazyLock;
11use tokio_boring::SslStream;
12
13mod cache;
14mod v0;
15#[cfg(feature = "hyper1")]
17pub mod v1;
18
19pub use self::v0::*;
20
21fn key_index() -> Result<Index<Ssl, SessionKey>, ErrorStack> {
22 static IDX: LazyLock<Index<Ssl, SessionKey>> = LazyLock::new(|| Ssl::new_ex_index().unwrap());
23 Ok(*IDX)
24}
25
26pub struct HttpsLayerSettings {
28 session_cache_capacity: usize,
29}
30
31impl HttpsLayerSettings {
32 #[must_use]
34 pub fn builder() -> HttpsLayerSettingsBuilder {
35 HttpsLayerSettingsBuilder(HttpsLayerSettings::default())
36 }
37}
38
39impl Default for HttpsLayerSettings {
40 fn default() -> Self {
41 Self {
42 session_cache_capacity: 8,
43 }
44 }
45}
46
47pub struct HttpsLayerSettingsBuilder(HttpsLayerSettings);
49
50impl HttpsLayerSettingsBuilder {
51 pub fn set_session_cache_capacity(&mut self, capacity: usize) {
54 self.0.session_cache_capacity = capacity;
55 }
56
57 #[must_use]
59 pub fn build(self) -> HttpsLayerSettings {
60 self.0
61 }
62}
63
64pub enum MaybeHttpsStream<T> {
66 Http(T),
68 Https(SslStream<T>),
70}
71
72impl<T> fmt::Debug for MaybeHttpsStream<T> {
73 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
74 match *self {
75 MaybeHttpsStream::Http(..) => f.pad("Http(..)"),
76 MaybeHttpsStream::Https(..) => f.pad("Https(..)"),
77 }
78 }
79}