userver: crypto::algorithm Namespace Reference
Loading...
Searching...
No Matches
crypto::algorithm Namespace Reference

Detailed Description

Miscellaneous cryptographic routines.

Classes

struct  StringsEqualConstTimeComparator
 Performs constant-time string comparison comparator. More...
 

Functions

bool AreStringsEqualConstTime (std::string_view str1, std::string_view str2) noexcept
 

Function Documentation

◆ AreStringsEqualConstTime()

bool crypto::algorithm::AreStringsEqualConstTime ( std::string_view str1,
std::string_view str2 )
noexcept

Performs constant-time string comparison if the strings are of equal size

#include <userver/storages/secdist/provider_component.hpp>
class UserPasswords {
public:
UserPasswords(const formats::json::Value& doc)
: user_passwords_(doc["user-passwords"].As<std::optional<Storage>>()) {}
bool IsMatching(const std::string& user, const Password& password) const {
if (!user_passwords_.has_value()) {
throw std::runtime_error(
"User passwords storage is missing. Field 'user-passwords' was "
"missing in json.");
}
const auto* ptr = utils::FindOrNullptr(user_passwords_.value(), user);
ptr->GetUnderlying(), password.GetUnderlying());
}
private:
using Storage = std::unordered_map<std::string, Password>;
std::optional<Storage> user_passwords_;
};