MXS-1662: Move mxs_crypt into utils

Moved the mxs_crypt function into utils and renamed to mxs::crypt (no C
code used it).
This commit is contained in:
Markus Mäkelä
2018-09-10 15:19:18 +03:00
parent d2f31aab0a
commit 40d73948a9
3 changed files with 26 additions and 17 deletions

View File

@ -42,6 +42,8 @@
#include <netinet/tcp.h>
#include <openssl/sha.h>
#include <thread>
#include <curl/curl.h>
#include <crypt.h>
#include <maxscale/alloc.h>
#include <maxscale/config.hh>
@ -1168,6 +1170,20 @@ int64_t get_total_memory()
namespace maxscale
{
std::string crypt(const std::string& password, const std::string& salt)
{
#if HAVE_GLIBC
struct crypt_data cdata;
cdata.initialized = 0;
return crypt_r(password.c_str(), salt.c_str(), &cdata);
#else
static std::mutex mxs_crypt_lock;
std::lock_guard<std::mutex> guard(mxs_crypt_lock);
std::string pw = crypt(password.c_str(), salt.c_str());
return pw;
#endif
}
std::string to_hex(uint8_t value)
{
std::string out;