From f23323701d8bb6bd0e051503681b37c12a85d4db Mon Sep 17 00:00:00 2001 From: James Chapman Date: Thu, 6 Jun 2024 15:05:06 +0100 Subject: [PATCH] feat: expose OpenSSL handles so that other code can create objects Previously X509HandleOpenSSL and KeyHandleOpenSSL were defined in openssl_supplier.cpp this made it difficult to create Handles from other OpenSSL code and use the methods in evse-security. Signed-off-by: James Chapman --- .../detail/openssl/openssl_handles.hpp | 36 +++++++++++++++++++ .../crypto/openssl/openssl_supplier.cpp | 25 +------------ 2 files changed, 37 insertions(+), 24 deletions(-) create mode 100644 include/evse_security/detail/openssl/openssl_handles.hpp diff --git a/include/evse_security/detail/openssl/openssl_handles.hpp b/include/evse_security/detail/openssl/openssl_handles.hpp new file mode 100644 index 0000000..d52a253 --- /dev/null +++ b/include/evse_security/detail/openssl/openssl_handles.hpp @@ -0,0 +1,36 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright Pionix GmbH and Contributors to EVerest +#pragma once + +#include +#include +#include +#include + +namespace evse_security { + +struct X509HandleOpenSSL : public X509Handle { + X509HandleOpenSSL(X509* certificate) : x509(certificate) { + } + + X509* get() { + return x509.get(); + } + +private: + X509_ptr x509; +}; + +struct KeyHandleOpenSSL : public KeyHandle { + KeyHandleOpenSSL(EVP_PKEY* key) : key(key) { + } + + EVP_PKEY* get() { + return key.get(); + } + +private: + EVP_PKEY_ptr key; +}; + +} // namespace evse_security diff --git a/lib/evse_security/crypto/openssl/openssl_supplier.cpp b/lib/evse_security/crypto/openssl/openssl_supplier.cpp index 72f82bb..de2be01 100644 --- a/lib/evse_security/crypto/openssl/openssl_supplier.cpp +++ b/lib/evse_security/crypto/openssl/openssl_supplier.cpp @@ -2,6 +2,7 @@ // Copyright Pionix GmbH and Contributors to EVerest #include +#include #include #include @@ -26,30 +27,6 @@ namespace evse_security { -struct X509HandleOpenSSL : public X509Handle { - X509HandleOpenSSL(X509* certificate) : x509(certificate) { - } - - X509* get() { - return x509.get(); - } - -private: - X509_ptr x509; -}; - -struct KeyHandleOpenSSL : public KeyHandle { - KeyHandleOpenSSL(EVP_PKEY* key) : key(key) { - } - - EVP_PKEY* get() { - return key.get(); - } - -private: - EVP_PKEY_ptr key; -}; - static X509* get(X509Handle* handle) { if (X509HandleOpenSSL* ssl_handle = dynamic_cast(handle)) { return ssl_handle->get();