-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathopenssl_common.cc
More file actions
32 lines (28 loc) · 811 Bytes
/
Copy pathopenssl_common.cc
File metadata and controls
32 lines (28 loc) · 811 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include "openssl_common.hpp"
#include <iomanip>
#include <sstream>
std::string toHex(const std::string &str)
{
std::stringstream ss;
ss << std::hex << std::setfill('0');
for (unsigned char c : str) {
ss << std::setw(2) << static_cast<int>(c);
}
return ss.str();
}
std::string fromHex(const std::string &str)
{
std::string result;
for (size_t i = 0; i < str.length(); i += 2) {
std::string byteString = str.substr(i, 2);
char byte = static_cast<char>(std::stoi(byteString, nullptr, 16));
result.push_back(byte);
}
return result;
}
void handleOpenSSLError()
{
char errorBuffer[256];
ERR_error_string_n(ERR_get_error(), errorBuffer, sizeof(errorBuffer));
throw std::runtime_error(std::string("OpenSSL error: ") + errorBuffer);
}