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