9#include <botan/tls_session_manager_hybrid.h>
18 const std::shared_ptr<Credentials_Manager>& credentials_manager,
19 const std::shared_ptr<RandomNumberGenerator>& rng,
20 bool prefer_tickets) :
22 m_stateful(std::move(stateful)),
23 m_stateless(credentials_manager, rng),
24 m_prefer_tickets(prefer_tickets) {
29 const std::optional<Session_ID>&
id,
30 bool tls12_no_ticket) {
31 auto create_ticket = [&]() -> std::optional<Session_Handle> {
36 auto ticket_handle = m_stateless.
establish(session,
id,
false );
38 ticket_handle->is_ticket(),
39 "Session_Manager_Stateless produced unexpected Session_Handle");
43 auto create_id = [&] {
48 id_handle.has_value(), id_handle->is_id(),
"Session_Manager_In_Memory produced unexpected Session_Handle");
52 std::function preferred = create_ticket;
53 std::function fallback = create_id;
55 if(!m_prefer_tickets) {
56 std::swap(preferred, fallback);
59 if(
auto result = preferred()) {
69 std::reference_wrapper<Session_Manager> preferred = m_stateless;
70 std::reference_wrapper<Session_Manager> fallback = *m_stateful;
72 if(!m_prefer_tickets) {
73 std::swap(preferred, fallback);
76 if(
auto session = preferred.get().retrieve(handle, callbacks, policy)) {
80 return fallback.get().retrieve(handle, callbacks, policy);
#define BOTAN_ASSERT_NONNULL(ptr)
#define BOTAN_ASSERT_IMPLICATION(expr1, expr2, msg)
bool is_pre_tls_13() const
Protocol_Version version() const
Helper class to embody a session handle in all protocol versions.
std::optional< Session > retrieve(const Session_Handle &handle, Callbacks &callbacks, const Policy &policy) override
Retrieves a specific session given a handle.
bool emits_session_tickets() override
Session_Manager_Hybrid(std::unique_ptr< Session_Manager > stateful_manager, const std::shared_ptr< Credentials_Manager > &credentials_manager, const std::shared_ptr< RandomNumberGenerator > &rng, bool prefer_tickets=true)
std::optional< Session_Handle > establish(const Session &session, const std::optional< Session_ID > &id=std::nullopt, bool tls12_no_ticket=false) override
Save a new Session and assign a Session_Handle (TLS Server)
std::optional< Session_Handle > establish(const Session &session, const std::optional< Session_ID > &id=std::nullopt, bool tls12_no_ticket=false) override
Save a new Session and assign a Session_Handle (TLS Server)
bool emits_session_tickets() override