#pragma once

#include "pch.h"

namespace SSLClient {

/// <summary>
/// SSL证书管理器
/// 负责加载和管理证书、私钥
/// </summary>
class CertificateManager
{
public:
	CertificateManager();
	~CertificateManager();

	// 禁止拷贝
	CertificateManager(const CertificateManager&) = delete;
	CertificateManager& operator=(const CertificateManager&) = delete;

	/// <summary>
	/// 从内存加载X509证书
	/// </summary>
	/// <param name="certPem">PEM格式的证书</param>
	/// <returns>X509证书对象，失败返回nullptr</returns>
	X509* LoadCertificateFromMemory(const char* certPem);

	/// <summary>
	/// 从内存加载私钥
	/// </summary>
	/// <param name="keyPem">PEM格式的私钥</param>
	/// <param name="password">私钥密码</param>
	/// <returns>EVP_PKEY对象，失败返回nullptr</returns>
	EVP_PKEY* LoadPrivateKeyFromMemory(const char* keyPem, const char* password);

	/// <summary>
	/// 打印OpenSSL错误信息
	/// </summary>
	/// <param name="message">错误描述</param>
	static void PrintSSLError(const char* message);
};

} // namespace SSLClient
