Cuberite
A lightweight, fast and extensible game server for Minecraft
X509Cert.cpp
Go to the documentation of this file.
1 
2 // X509Cert.cpp
3 
4 // Implements the cX509Cert class representing a wrapper over X509 certs in mbedTLS
5 
6 #include "Globals.h"
7 #include "X509Cert.h"
8 
9 
10 
11 
12 
14 {
15  mbedtls_x509_crt_init(&m_Cert);
16 }
17 
18 
19 
20 
21 
23 {
24  mbedtls_x509_crt_free(&m_Cert);
25 }
26 
27 
28 
29 
30 
31 int cX509Cert::Parse(const void * a_CertContents, size_t a_Size)
32 {
33  // mbedTLS requires that PEM-encoded data is passed including the terminating NUL byte,
34  // and DER-encoded data is decoded properly even with an extra trailing NUL byte, so we simply add one to everything:
35  AString certContents(static_cast<const char *>(a_CertContents), a_Size);
36  return mbedtls_x509_crt_parse(&m_Cert, reinterpret_cast<const unsigned char *>(certContents.data()), a_Size + 1);
37 }
38 
39 
40 
41 
std::string AString
Definition: StringUtils.h:11
mbedtls_x509_crt m_Cert
Definition: X509Cert.h:32
int Parse(const void *a_CertContents, size_t a_Size)
Parses the certificate chain data into the context.
Definition: X509Cert.cpp:31
cX509Cert(void)
Definition: X509Cert.cpp:13
~cX509Cert(void)
Definition: X509Cert.cpp:22