Files
encryptsql/include/kms/kms_interface.hpp
blue-lemon0104 0120fa9ce3 init
2026-04-07 13:35:22 +08:00

55 lines
1.6 KiB
C++
Executable File

// kms_interface.hpp
#ifndef KMS_INTERFACE_HPP
#define KMS_INTERFACE_HPP
#include <memory>
#include <functional>
#include "ikms_core.hpp"
namespace myPtr{
template <typename T, typename... Args>
std::unique_ptr<T> make_unique(Args&&... args) {
return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
}
}
// 静态库接口类
class KMSInterface {
private:
static thread_local std::unique_ptr<IKmsCore> instance_;
public:
// 初始化并"创建" IKmsCore 实例
static bool initialize( const IKmsConfig& config );
static void cleanup(); // 清理当前线程绑定的 core 实例
// 获取当前线程的 KMS 实例(如需特殊用途)
static IKmsCore* getInstance();
// 包装接口
static bool hasCmk(const std::string& user_name);
static bool createCmk(const std::string& user_name, int rotate_period,
KeyStruct ks = KeyStruct::RAW, AlgorithmType alg = AlgorithmType::AES128);
static bool deleteCmk(const std::string& user_name);
static bool describeCmk(const std::string &user_name, std::string &result, bool decrypt);
// 轮转相关
static bool rotateCmkNow(const std::string& user_name);
static bool handleAutoRotateCmd(std::string* action, const std::string& user_name);
static bool getCmkAutoRotateStatusByUsername(const std::string& user_name);
// 加解密
static bool encryptData(std::string& dek);
static bool decryptData(std::string& dek);
// 创建DEK
static bool createDek(std::string &col_dek, const std::string &column_name);
};
#endif // KMS_INTERFACE_HPP