From 4d1cf701001591f087e8630f0e30838ed8b60338 Mon Sep 17 00:00:00 2001 From: neru Date: Tue, 12 May 2026 16:23:42 -0300 Subject: [PATCH] feat: add WolfSSL RAAI helper functions --- src/proxy/tinymitm/raai-helper.cpp | 33 ++++++++++++++++++++++++++++++ src/proxy/tinymitm/raai-helper.h | 14 +++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 src/proxy/tinymitm/raai-helper.cpp create mode 100644 src/proxy/tinymitm/raai-helper.h diff --git a/src/proxy/tinymitm/raai-helper.cpp b/src/proxy/tinymitm/raai-helper.cpp new file mode 100644 index 0000000..51661a6 --- /dev/null +++ b/src/proxy/tinymitm/raai-helper.cpp @@ -0,0 +1,33 @@ +#include "raai-helper.h" + +#include +#include + +#include +#include + +void WolfSSLDeleter::operator()(WC_RNG* rng) +{ + if (rng) + { + wc_FreeRng(rng); + delete r; + } +} +void WolfSSLDeleter::operator()(RsaKey* key) +{ + if (key) + { + wc_FreeRsaKey(key); + delete k; + } +} +void WolfSSLDeleter::operator()(WOLFSSL_CTX* ctx) +{ + if (ctx) wolfSSL_CTX_free(ctx); +} + +void WolfSSLDeleter::operator()(WOLFSSL* ssl) +{ + if (ssl) wolfSSL_free(ssl); +} diff --git a/src/proxy/tinymitm/raai-helper.h b/src/proxy/tinymitm/raai-helper.h new file mode 100644 index 0000000..aec8098 --- /dev/null +++ b/src/proxy/tinymitm/raai-helper.h @@ -0,0 +1,14 @@ +#pragma once + +struct WC_RNG; +struct RsaKey; +struct WOLFSSL_CTX; +struct WOLFSSL; + +struct WolfSSLDeleter +{ + void operator()(WC_RNG* rng); + void operator()(RsaKey* key); + void operator()(WOLFSSL_CTX* ctx); + void operator()(WOLFSSL* ssl); +};