Skip to content

Commit

Permalink
feat: expose OpenSSL handles so that other code can create objects (#80)
Browse files Browse the repository at this point in the history
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.

feat: X509HandleOpenSSL and KeyHandleOpenSSL moved to openssl_types.hpp

This enables external OpenSSL code to create objects that can be
used via the AbstractCryptoSupplier interface.

Signed-off-by: James Chapman <[email protected]>
  • Loading branch information
james-ctc authored Jun 7, 2024
1 parent aa79e39 commit f8be032
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 24 deletions.
27 changes: 27 additions & 0 deletions include/evse_security/detail/openssl/openssl_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,31 @@ using BIO_ptr = std::unique_ptr<BIO>;
using EVP_MD_CTX_ptr = std::unique_ptr<EVP_MD_CTX>;
using EVP_ENCODE_CTX_ptr = std::unique_ptr<EVP_ENCODE_CTX>;

struct X509Handle;
struct KeyHandle;

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
24 changes: 0 additions & 24 deletions lib/evse_security/crypto/openssl/openssl_supplier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,30 +26,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<X509HandleOpenSSL*>(handle)) {
return ssl_handle->get();
Expand Down

0 comments on commit f8be032

Please sign in to comment.