Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
Providers/OpenSSL/Certificate.h
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4#ifndef _Stroika_Foundation_Cryptography_OpenSSL_Certificate_h_
5#define _Stroika_Foundation_Cryptography_OpenSSL_Certificate_h_ 1
6
7#include "Stroika/Foundation/StroikaPreComp.h"
8
9#include <memory>
10
11#if qStroika_HasComponent_OpenSSL
12#include <openssl/ssl.h>
13#include <openssl/x509.h>
14#endif
15
16#include "Stroika/Foundation/Common/Common.h"
17#include "Stroika/Foundation/Cryptography/PKI/Certificate.h"
18#include "Stroika/Foundation/Cryptography/Providers/OpenSSL/PrivateKey.h"
19
20namespace Stroika::Foundation::Cryptography::Providers::OpenSSL::Certificate {
21
22 using namespace Cryptography::PKI::Certificate;
23
24#if qStroika_HasComponent_OpenSSL
25 /**
26 */
27 struct LibRepType : unique_ptr<::X509, decltype (&::X509_free)> {
28 using inherited = unique_ptr<::X509, decltype (&::X509_free)>;
29
30 LibRepType (nullptr_t);
31 LibRepType (LibRepType&&) = default;
32 LibRepType (X509* p);
33 };
34
35 /**
36 */
37 struct IRep : Cryptography::PKI::Certificate::IRep {
38 virtual X509* Get_X509 () const = 0;
39 };
40
41 /**
42 */
43 struct Ptr : shared_ptr<IRep> {
44 using inherited = shared_ptr<IRep>;
45 /**
46 * (1) normal shared_ptr constructors supported
47 * (2) copy from const shared_ptr<IRep>&, to clarify overload avoid ambiguity
48 * (3) shared_ptr<PKI::Certificate::IRep>& - a dynamic_pointer_cast - which only works - which throws if not the right type
49 */
50 using inherited::inherited;
51 Ptr (const shared_ptr<IRep>& p);
52 Ptr (const shared_ptr<PKI::Certificate::IRep>& p);
53
54 /**
55 */
56 X509* Get_X509 () const;
57 };
58
59 /**
60 * \brief Construct a Certificate object
61 * (1) from an adopted unique_ptr to the underlying library object
62 * (2) from generate a new self-signed certificate (and private key)
63 * \see https://stackoverflow.com/questions/256405/programmatically-create-x509-certificate-using-openssl
64 */
65 Ptr New (LibRepType&& x509);
66 tuple<OpenSSL::PrivateKey::Ptr, Ptr> New (const SelfSignedCertParams& params);
67#endif
68
69}
70
71/*
72 ********************************************************************************
73 ***************************** Implementation Details ***************************
74 ********************************************************************************
75 */
76#include "Certificate.inl"
77
78#endif /*_Stroika_Foundation_Cryptography_OpenSSL_Certificate_h_*/