#ifndef SLEELA_HTTP3_CRYPTO_HPP #define SLEELA_HTTP3_CRYPTO_HPP #include "crypto_openssl.h" #include "crypto_route_session.h" #include #include #include #include namespace sleela::http3 { class RouteSession final { public: RouteSession() = default; ~RouteSession() { http3_route_session_clear(&session_); } RouteSession(const RouteSession&) = delete; RouteSession& operator=(const RouteSession&) = delete; std::array establish( const http3_route_plan_t& plan, const std::array& peer_public_key, std::uint64_t key_epoch) { if (http3_route_session_establish(&session_, &plan, peer_public_key.data(), key_epoch) != 0) { throw std::runtime_error("HTTP/3 route session establishment failed"); } return public_key(); } std::array rekey( const http3_route_plan_t& old_plan, const http3_route_plan_t& new_plan, const std::array& peer_public_key, std::uint64_t key_epoch) { if (http3_route_session_rekey(&session_, &old_plan, &new_plan, peer_public_key.data(), key_epoch) != 0) { throw std::runtime_error("HTTP/3 route session rekey failed"); } return public_key(); } std::array country_key(std::uint32_t country_id) const { std::array key{}; if (http3_route_session_derive_country_key(&session_, country_id, key.data()) != 0) { throw std::runtime_error("HTTP/3 country key derivation failed"); } return key; } void clear() noexcept { http3_route_session_clear(&session_); } private: std::array public_key() const { std::array key{}; std::copy(std::begin(session_.ephemeral_public_key), std::end(session_.ephemeral_public_key), key.begin()); return key; } http3_route_session_t session_{}; }; } // namespace sleela::http3 #endif