
/*
 * 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.
 */

// CallbackSslContext.cpp

// Declares the cCallbackSslContext class representing a SSL context wrapper that uses callbacks to read and write SSL peer data

#include "Globals.h"
#include "CallbackSslContext.h"





cCallbackSslContext::cCallbackSslContext(void) :
	m_Callbacks(nullptr)
{
	// Nothing needed, but the constructor needs to exist so
}





cCallbackSslContext::cCallbackSslContext(cCallbackSslContext::cDataCallbacks & a_Callbacks) :
	m_Callbacks(&a_Callbacks)
{
}





int cCallbackSslContext::ReceiveEncrypted(unsigned char * a_Buffer, size_t a_NumBytes)
{
	if (m_Callbacks == nullptr)
	{
		LOGWARNING("SSL: Trying to receive data with no callbacks, aborting.");
		return MBEDTLS_ERR_NET_RECV_FAILED;
	}
	return m_Callbacks->ReceiveEncrypted(a_Buffer, a_NumBytes);
}





int cCallbackSslContext::SendEncrypted(const unsigned char * a_Buffer, size_t a_NumBytes)
{
	if (m_Callbacks == nullptr)
	{
		LOGWARNING("SSL: Trying to send data with no callbacks, aborting.");
		return MBEDTLS_ERR_NET_SEND_FAILED;
	}
	return m_Callbacks->SendEncrypted(a_Buffer, a_NumBytes);
}





