53 lines
1.9 KiB
C++
53 lines
1.9 KiB
C++
// sign_shim_unix.cpp - Linux/macOS adapter for libsign.a's C interface
|
|
//
|
|
// libsign.a 公开 ABI 是 C linkage(避免 std::string 跨编译器/跨 libstdc++
|
|
// 版本 ABI 风险),但 YAMA 客户端代码(IOCPClient.cpp / KernelManager.cpp /
|
|
// linux/main.cpp / macos/main.mm)习惯用 std::string 调用 signMessage /
|
|
// verifyMessage。本文件提供 C++ 适配,让两边契合。
|
|
//
|
|
// Windows 不编译这个文件——Windows 直接链接私有 .lib 提供的 std::string 版本。
|
|
|
|
#include <string>
|
|
#include <cstring>
|
|
|
|
// libsign.a 提供的 C 接口
|
|
extern "C" {
|
|
int signMessage_c(const char* privateKey, int privateKeyLen,
|
|
const unsigned char* msg, int msgLen,
|
|
char* outBuf, int outBufSize);
|
|
int verifyMessage_c(const char* publicKey, int publicKeyLen,
|
|
const unsigned char* msg, int msgLen,
|
|
const char* sigHex, int sigLen);
|
|
int isVerifyCalled_c(void);
|
|
}
|
|
|
|
// 与 YAMA common/commands.h 中 BYTE 一致
|
|
typedef unsigned char BYTE;
|
|
|
|
// ============================================================================
|
|
// 提供 YAMA 既有声明所期望的 C++ 符号
|
|
// ============================================================================
|
|
|
|
std::string signMessage(const std::string& privateKey, BYTE* msg, int len)
|
|
{
|
|
char buf[65] = {};
|
|
int n = signMessage_c(privateKey.c_str(), (int)privateKey.size(),
|
|
msg, len,
|
|
buf, sizeof(buf));
|
|
if (n != 64) return std::string();
|
|
return std::string(buf, 64);
|
|
}
|
|
|
|
bool verifyMessage(const std::string& publicKey, BYTE* msg, int len,
|
|
const std::string& signature)
|
|
{
|
|
return verifyMessage_c(publicKey.c_str(), (int)publicKey.size(),
|
|
msg, len,
|
|
signature.data(), (int)signature.size()) != 0;
|
|
}
|
|
|
|
int isVerifyCalled()
|
|
{
|
|
return isVerifyCalled_c();
|
|
}
|