
/*
 * Copyright 2011-2022 Cuberite Contributors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

// X509Cert.cpp

// Implements the cX509Cert class representing a wrapper over X509 certs in mbedTLS

#include "Globals.h"
#include "X509Cert.h"





cX509Cert::cX509Cert(void)
{
	mbedtls_x509_crt_init(&m_Cert);
}





cX509Cert::~cX509Cert()
{
	mbedtls_x509_crt_free(&m_Cert);
}





int cX509Cert::Parse(const void * a_CertContents, size_t a_Size)
{
	// mbedTLS requires that PEM-encoded data is passed including the terminating NUL byte,
	// and DER-encoded data is decoded properly even with an extra trailing NUL byte, so we simply add one to everything:
	AString certContents(static_cast<const char *>(a_CertContents), a_Size);
	return mbedtls_x509_crt_parse(&m_Cert, reinterpret_cast<const unsigned char *>(certContents.data()), a_Size + 1);
}




