userver: userver/crypto/certificate.hpp Source File
⚠️ This is the documentation for an old userver version. Click here to switch to the latest version.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
certificate.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/crypto/certificate.hpp
4/// @brief @copybrief crypto::Certificate
5
6#include <memory>
7#include <string_view>
8
9#include <userver/crypto/basic_types.hpp>
10
11USERVER_NAMESPACE_BEGIN
12
13namespace crypto {
14
15/// @ingroup userver_universal userver_containers
16///
17/// Loaded into memory X509 certificate
19 public:
20 using NativeType = X509;
21
22 Certificate() = default;
23
24 NativeType* GetNative() const noexcept { return cert_.get(); }
25 explicit operator bool() const noexcept { return !!cert_; }
26
27 /// Accepts a string that contains a certificate, checks that
28 /// it's correct, loads it into OpenSSL structures and returns as a
29 /// Certificate variable.
30 ///
31 /// @throw crypto::KeyParseError if failed to load the certificate.
32 static Certificate LoadFromString(std::string_view certificate);
33
34 private:
35 explicit Certificate(std::shared_ptr<NativeType> cert)
36 : cert_(std::move(cert)) {}
37
38 std::shared_ptr<NativeType> cert_;
39};
40
41} // namespace crypto
42
43USERVER_NAMESPACE_END