userver
C++ Async Framework
Toggle main menu visibility
Loading...
Searching...
No Matches
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
<
list
>
7
#
include
<
memory
>
8
#
include
<
optional
>
9
#
include
<
string
>
10
#
include
<
string_view
>
11
12
#
include
<
userver
/
crypto
/
basic_types
.
hpp
>
13
14
USERVER_NAMESPACE_BEGIN
15
16
namespace
crypto {
17
18
/// @ingroup userver_universal userver_containers
19
///
20
/// Loaded into memory X509 certificate
21
class
Certificate
{
22
public
:
23
using
NativeType = X509;
24
25
Certificate() =
default
;
26
27
NativeType* GetNative()
const
noexcept
{
return
cert_.get(); }
28
explicit
operator
bool
()
const
noexcept
{
return
!!cert_; }
29
30
/// Returns a PEM-encoded representation of stored certificate.
31
///
32
/// @throw crypto::SerializationError if serialization fails.
33
std::optional<std::string>
GetPemString
()
const
;
34
35
/// Accepts a string that contains a certificate, checks that
36
/// it's correct, loads it into OpenSSL structures and returns as a
37
/// Certificate variable.
38
///
39
/// @throw crypto::KeyParseError if failed to load the certificate.
40
static
Certificate
LoadFromString
(std::string_view certificate);
41
/// Loads the certificate and skips the meta information in it
42
/// @throw crypto::KeyParseError if failed to load the certificate.
43
static
Certificate
LoadFromStringSkippingAttributes
(std::string_view certificate);
44
45
/// Returns Subject
46
std::string
GetSubject
()
const
;
47
48
private
:
49
explicit
Certificate(std::shared_ptr<NativeType> cert)
50
: cert_(std::move(cert))
51
{}
52
53
std::shared_ptr<NativeType> cert_;
54
};
55
56
using
CertificatesChain = std::list<
Certificate
>;
57
58
/// Accepts a string that contains a chain of certificates (primary and intermediate), checks that
59
/// it's correct, loads it into OpenSSL structures and returns as a
60
/// list of 'Certificate's.
61
///
62
/// @throw crypto::KeyParseError if failed to load the certificate.
63
CertificatesChain
LoadCertificatesChainFromString
(std::string_view chain);
64
65
}
// namespace crypto
66
67
USERVER_NAMESPACE_END
userver
crypto
certificate.hpp
Generated on
for userver by
Doxygen
1.17.0