4#include "Stroika/Foundation/StroikaPreComp.h"
6#if qStroika_HasComponent_OpenSSL
7#include <openssl/err.h>
8#include <openssl/evp.h>
11#include "Stroika/Foundation/Containers/Common.h"
13#include "Stroika/Foundation/Execution/Common.h"
20using namespace Stroika::Foundation::Cryptography;
21using namespace Stroika::Foundation::Cryptography::Providers::OpenSSL;
22using namespace Stroika::Foundation::Memory;
26#if qStroika_HasComponent_OpenSSL
28 Synchronized<bool> sNamesSupported_{
true};
29 Synchronized<bool> sNamesLoaded_{
false};
31 struct ErrStringIniter_ {
34 if (sNamesSupported_) {
35 auto l = sNamesLoaded_.
rwget ();
36 if (
static_cast<bool> (l)) {
42 } _InitOpenSSLErrStrings_;
43 void LoadStringsIfNeeded_ ()
45 if (not sNamesLoaded_ and sNamesSupported_) {
46 auto l = sNamesLoaded_.rwget ();
47 if (not
static_cast<bool> (l)) {
48 ERR_load_crypto_strings ();
60Exception::Exception (InternalErrorCodeType errorCode)
61 : inherited{GetMessage (errorCode)}
62 , fErrorCode_{errorCode}
66Exception::InternalErrorCodeType Exception::GetErrorCode ()
const
73 LoadStringsIfNeeded_ ();
76 ::ERR_error_string_n (errorCode, buf, NEltsOf (buf));
80[[noreturn]]
void Exception::ThrowLastError ()
82 Execution::Throw (Exception{ERR_get_error ()});
85bool Exception::GetNamesSupported ()
87 return sNamesSupported_.load ();
90void Exception::SetNamesSupported (
bool openSSLStringsSupported)
92 auto l = sNamesSupported_.rwget ();
93 if (
static_cast<bool> (l) != openSSLStringsSupported) {
94 if (openSSLStringsSupported) {
98 auto lNamesLoaded = sNamesLoaded_.rwget ();
99 if (
static_cast<bool> (l)) {
101 lNamesLoaded =
false;
104 sNamesSupported_ = openSSLStringsSupported;
String is like std::u32string, except it is much easier to use, often much more space efficient,...
static String FromNarrowSDKString(const char *from)
Wrap any object with Synchronized<> and it can be used similarly to the base type,...
nonvirtual WritableReference rwget()
get a read-write smart pointer to the underlying Synchronized<> object, holding the full lock the who...