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