std::string hashPassword(const std::string& password)
{
-#ifdef HAVE_LIBSODIUM
+#ifdef HAVE_CRYPTO_PWHASH_STR
std::string result;
result.resize(crypto_pwhash_STRBYTES);
sodium_mlock(result.data(), result.size());
bool verifyPassword(const std::string& hash, const std::string& password)
{
-#ifdef HAVE_LIBSODIUM
+#ifdef HAVE_CRYPTO_PWHASH_STR
if (hash.size() > crypto_pwhash_STRBYTES) {
throw std::runtime_error("Invalid password hash supplied for verification, size is " + std::to_string(hash.size()) + ", expected at most " + std::to_string(crypto_pwhash_STRBYTES));
}
bool isPasswordHashed(const std::string& password)
{
-#ifdef HAVE_LIBSODIUM
+#ifdef HAVE_CRYPTO_PWHASH_STR
if (password.size() > crypto_pwhash_STRBYTES) {
return false;
}
bool CredentialsHolder::isHashingAvailable()
{
-#ifdef HAVE_LIBSODIUM
+#ifdef HAVE_CRYPTO_PWHASH_STR
return true;
#else
return false;
BOOST_AUTO_TEST_SUITE(credentials_cc)
-#ifdef HAVE_LIBSODIUM
+#ifdef HAVE_CRYPTO_PWHASH_STR
BOOST_AUTO_TEST_CASE(test_CredentialsUtils)
{
const std::string plaintext("test");
BOOST_CHECK(!holder.matches("not test"));
BOOST_CHECK(!holder.wasHashed());
-#ifdef HAVE_LIBSODIUM
+#ifdef HAVE_CRYPTO_PWHASH_STR
BOOST_CHECK(CredentialsHolder::isHashingAvailable());
const std::string sampleHash("$argon2id$v=19$m=65536,t=2,p=1$ndQKu3+ZsWedqRrlNFUaNw$tnb0MJVe5C2hlqkDt0Ln3R6VKCYkfMYdxDy+puXes3s");