Security: add a public CSPRNG bytes API (VL-SEC-01)
This commit is contained in:
1 parent
0002e74a7d
commit
54d143be93
3 files changed
+56
No files matched your search
@@ -186,6 +186,24 @@ namespace Void::Security
|
||||
return encoded;
|
||||
}
|
||||
|
||||
Void::Result::Result<void> random_bytes(std::span<unsigned char> buffer)
|
||||
{
|
||||
if (const auto initialized = ensure_sodium(); !initialized) {
|
||||
return std::unexpected{initialized.error()};
|
||||
}
|
||||
if (buffer.empty()) {
|
||||
return {};
|
||||
}
|
||||
if (auto fault = Detail::maybe_inject_fault(
|
||||
FaultOperation::random_bytes, "Security::random_bytes");
|
||||
fault.has_value()) {
|
||||
wipe_bytes(buffer);
|
||||
return std::unexpected{std::move(*fault)};
|
||||
}
|
||||
randombytes_buf(buffer.data(), buffer.size());
|
||||
return {};
|
||||
}
|
||||
|
||||
Void::Result::Result<std::string> hash_token(std::string_view token)
|
||||
{
|
||||
if (const auto initialized = ensure_sodium(); !initialized) {
|
||||
|
||||
Reference in new issue
Block a user