mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 22:48:11 +00:00
LibTLS: Move singleton for DefaultRootCACertificates out of line
This follows the pattern of every other singleton in the system.
Also, remove use of AK::Singleton in place of a function-scope static.
There are only three uses of that class outside of the Kernel, and all
the remaining uses are suspect. We need it in the Kernel because we
want to avoid global destructors to prevent nasty surprises about
expected lifetimes of objects. In Userland, we have normal thread-safe
statics available. 7d11edbe1
attempted to standardize the pattern, but
it seems like more uses of awkward singleton creation have crept in or
were missed back then.
As a bonus, this fixes a linker error on macOS with -g -O0 for Lagom
WebContent.
This commit is contained in:
parent
05dd46f9e3
commit
6266976e7a
2 changed files with 7 additions and 5 deletions
|
@ -9,7 +9,6 @@
|
|||
#include <AK/ByteBuffer.h>
|
||||
#include <AK/Forward.h>
|
||||
#include <AK/Optional.h>
|
||||
#include <AK/Singleton.h>
|
||||
#include <AK/Types.h>
|
||||
#include <LibCore/ConfigFile.h>
|
||||
#include <LibCore/DateTime.h>
|
||||
|
@ -295,11 +294,9 @@ public:
|
|||
static ErrorOr<Vector<Certificate>> parse_pem_root_certificate_authorities(ByteBuffer&);
|
||||
static ErrorOr<Vector<Certificate>> load_certificates();
|
||||
|
||||
static DefaultRootCACertificates& the() { return s_the; }
|
||||
static DefaultRootCACertificates& the();
|
||||
|
||||
private:
|
||||
static Singleton<DefaultRootCACertificates> s_the;
|
||||
|
||||
Vector<Certificate> m_ca_certificates;
|
||||
};
|
||||
|
||||
|
|
|
@ -489,7 +489,6 @@ Vector<Certificate> TLSv12::parse_pem_certificate(ReadonlyBytes certificate_pem_
|
|||
return { move(certificate) };
|
||||
}
|
||||
|
||||
Singleton<DefaultRootCACertificates> DefaultRootCACertificates::s_the;
|
||||
DefaultRootCACertificates::DefaultRootCACertificates()
|
||||
{
|
||||
auto load_result = load_certificates();
|
||||
|
@ -501,6 +500,12 @@ DefaultRootCACertificates::DefaultRootCACertificates()
|
|||
m_ca_certificates = load_result.release_value();
|
||||
}
|
||||
|
||||
DefaultRootCACertificates& DefaultRootCACertificates::the()
|
||||
{
|
||||
static DefaultRootCACertificates s_the;
|
||||
return s_the;
|
||||
}
|
||||
|
||||
ErrorOr<Vector<Certificate>> DefaultRootCACertificates::load_certificates()
|
||||
{
|
||||
auto cacert_file = TRY(Core::File::open("/etc/cacert.pem"sv, Core::File::OpenMode::Read));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue