Update
CI / GCC 16 / C++26 / default (push) Has been cancelled
CI / GCC 16 / C++26 / sanitizers (push) Has been cancelled
CI / GCC 16 / C++26 / werror (push) Has been cancelled

Signed-off-by: faumaray <faumaray@gmail.com>
This commit is contained in:
faumaray committed 2026-07-15 19:49:06 +03:00
1 parent fa30098129
commit 8583a479dd
11 files changed
+1763 -129

No files matched your search

+46
View File
@@ -0,0 +1,46 @@
#pragma once
#include <Void/Functional/Result.hpp>
#include <cstddef>
#include <string>
#include <string_view>
namespace Void::Security
{
/// Cost presets supplied by libsodium for Argon2id password hashing.
/// Moderate is the default for stored account passwords; Interactive is
/// useful where latency and memory are constrained, including tests.
enum class PasswordHashStrength { Interactive, Moderate, Sensitive };
inline constexpr std::size_t default_token_entropy_bytes = 32;
/// Generate a URL-safe, unpadded token containing `entropy_bytes` of
/// cryptographically secure randomness.
[[nodiscard]] Void::Result::Result<std::string>
random_token(std::size_t entropy_bytes = default_token_entropy_bytes);
/// Produce a deterministic lowercase hexadecimal BLAKE2b-256 digest.
/// Store this digest instead of the bearer token itself.
[[nodiscard]] Void::Result::Result<std::string>
hash_token(std::string_view token);
/// Verify a token digest without data-dependent comparison timing.
/// Malformed digests are treated as a non-match.
[[nodiscard]] Void::Result::Result<bool>
verify_token(std::string_view token, std::string_view encoded_hash);
/// Hash a password using libsodium's Argon2id encoded-string format.
/// The returned string contains the algorithm, parameters, salt, and hash.
[[nodiscard]] Void::Result::Result<std::string> hash_password(
std::string_view password,
PasswordHashStrength strength = PasswordHashStrength::Moderate);
/// Verify a password against a libsodium Argon2id encoded hash.
/// Malformed hashes are treated as a non-match.
[[nodiscard]] Void::Result::Result<bool>
verify_password(std::string_view password,
std::string_view encoded_hash);
} // namespace Void::Security