Add reusable strict JSON, rate limiting, and sealed secrets

This commit is contained in:
faumaray committed 2026-07-29 22:40:15 +03:00
1 parent 7edce967f2
commit 4c2b96ac69
10 files changed
+778 -40

No files matched your search

+21
View File
@@ -2,9 +2,12 @@
#include <Void/Functional/Result.hpp>
#include <array>
#include <cstddef>
#include <span>
#include <string>
#include <string_view>
#include <vector>
namespace Void::Security
{
@@ -15,6 +18,10 @@ namespace Void::Security
enum class PasswordHashStrength { Interactive, Moderate, Sensitive };
inline constexpr std::size_t default_token_entropy_bytes = 32;
inline constexpr std::size_t secret_key_bytes = 32;
inline constexpr std::size_t secret_nonce_bytes = 24;
inline constexpr std::size_t secret_authentication_bytes = 16;
using SecretKey = std::array<unsigned char, secret_key_bytes>;
/// Generate a URL-safe, unpadded token containing `entropy_bytes` of
/// cryptographically secure randomness.
@@ -43,4 +50,18 @@ namespace Void::Security
verify_password(std::string_view password,
std::string_view encoded_hash);
/// Generate a cryptographically random key for local secret encryption.
[[nodiscard]] Void::Result::Result<SecretKey> random_secret_key();
/// Encrypt and authenticate bytes. The returned portable envelope is
/// nonce || ciphertext || authentication tag.
[[nodiscard]] Void::Result::Result<std::vector<unsigned char>>
seal_secret(std::span<const unsigned char> plaintext,
const SecretKey& key);
/// Authenticate and decrypt an envelope produced by seal_secret.
[[nodiscard]] Void::Result::Result<std::vector<unsigned char>>
open_secret(std::span<const unsigned char> envelope,
const SecretKey& key);
} // namespace Void::Security