Skip to content

Commit

Permalink
fix: addressing PR review comment change to provide utility function …
Browse files Browse the repository at this point in the history
…to create Handle

Signed-off-by: James Chapman <[email protected]>
  • Loading branch information
james-ctc committed Jun 7, 2024
1 parent f233237 commit fa7d732
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 37 deletions.
4 changes: 4 additions & 0 deletions include/evse_security/crypto/openssl/openssl_supplier.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#pragma once

#include <evse_security/crypto/interface/crypto_supplier.hpp>
#include <openssl/x509.h>

namespace evse_security {

Expand Down Expand Up @@ -51,6 +52,9 @@ class OpenSSLSupplier : public AbstractCryptoSupplier {

static bool base64_encode_from_bytes(const std::vector<std::uint8_t>& bytes, std::string& out_encoded);
static bool base64_encode_from_string(const std::string& string, std::string& out_encoded);

static X509Handle X509Handle_from_X509(X509* certificate);
static X509Handle_ptr X509Handle_ptr_from_X509(X509* certificate);
};

} // namespace evse_security
36 changes: 0 additions & 36 deletions include/evse_security/detail/openssl/openssl_handles.hpp

This file was deleted.

33 changes: 32 additions & 1 deletion lib/evse_security/crypto/openssl/openssl_supplier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Copyright Pionix GmbH and Contributors to EVerest
#include <evse_security/crypto/openssl/openssl_supplier.hpp>

#include <evse_security/detail/openssl/openssl_handles.hpp>
#include <evse_security/detail/openssl/openssl_types.hpp>
#include <evse_security/utils/evse_filesystem.hpp>

Expand All @@ -27,6 +26,30 @@

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<X509HandleOpenSSL*>(handle)) {
return ssl_handle->get();
Expand Down Expand Up @@ -901,4 +924,12 @@ bool OpenSSLSupplier::base64_encode_from_string(const std::string& string, std::
return base64_encode(reinterpret_cast<const unsigned char*>(string.data()), string.size(), out_encoded);
}

X509Handle OpenSSLSupplier::X509Handle_from_X509(X509* certificate) {
return X509HandleOpenSSL(certificate);
}

X509Handle_ptr OpenSSLSupplier::X509Handle_ptr_from_X509(X509* certificate) {
return std::make_unique<X509HandleOpenSSL>(certificate);
}

} // namespace evse_security

0 comments on commit fa7d732

Please sign in to comment.