ClickHouse/src/Common/OpenSSLHelpers.cpp

32 lines
683 B
C++
Raw Normal View History

2019-09-11 11:21:54 +00:00
#include <Common/config.h>
#if USE_SSL
2019-05-26 06:52:29 +00:00
#include "OpenSSLHelpers.h"
#include <ext/scope_guard.h>
#include <openssl/err.h>
#include <openssl/sha.h>
2019-05-26 06:52:29 +00:00
namespace DB
{
2019-12-15 06:34:43 +00:00
#pragma GCC diagnostic warning "-Wold-style-cast"
2019-05-26 06:52:29 +00:00
void encodeSHA256(const std::string_view & text, unsigned char * out)
{
SHA256_CTX ctx;
SHA256_Init(&ctx);
SHA256_Update(&ctx, reinterpret_cast<const UInt8 *>(text.data()), text.size());
SHA256_Final(out, &ctx);
}
2019-05-26 06:52:29 +00:00
String getOpenSSLErrors()
{
BIO * mem = BIO_new(BIO_s_mem());
SCOPE_EXIT(BIO_free(mem));
ERR_print_errors(mem);
char * buf = nullptr;
2020-03-18 03:27:32 +00:00
size_t size = BIO_get_mem_data(mem, &buf);
2019-05-26 06:52:29 +00:00
return String(buf, size);
}
}
2019-09-11 11:21:54 +00:00
#endif