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<Result<Index<Ssl, SessionKey>, ErrorStack>> =
19 LazyLock::new(Ssl::new_ex_index);
20 IDX.clone()
21}
22
23pub struct HttpsLayerSettings {
25 session_cache_capacity: usize,
26}
27
28impl HttpsLayerSettings {
29 #[must_use]
31 pub fn builder() -> HttpsLayerSettingsBuilder {
32 HttpsLayerSettingsBuilder(HttpsLayerSettings::default())
33 }
34}
35
36impl Default for HttpsLayerSettings {
37 fn default() -> Self {
38 Self {
39 session_cache_capacity: 8,
40 }
41 }
42}
43
44pub struct HttpsLayerSettingsBuilder(HttpsLayerSettings);
46
47impl HttpsLayerSettingsBuilder {
48 pub fn set_session_cache_capacity(&mut self, capacity: usize) {
51 self.0.session_cache_capacity = capacity;
52 }
53
54 #[must_use]
56 pub fn build(self) -> HttpsLayerSettings {
57 self.0
58 }
59}
60
61pub enum MaybeHttpsStream<T> {
63 Http(T),
65 Https(SslStream<T>),
67}
68
69impl<T> fmt::Debug for MaybeHttpsStream<T> {
70 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
71 match *self {
72 MaybeHttpsStream::Http(..) => f.pad("Http(..)"),
73 MaybeHttpsStream::Https(..) => f.pad("Https(..)"),
74 }
75 }
76}