Add more Rand helper methods

PiperOrigin-RevId: 491409479
This commit is contained in:
Janusz Sobczak
2022-11-28 12:14:19 -08:00
committed by Copybara-Service
parent 2012acdbcc
commit 0cb5b004e4
3 changed files with 50 additions and 1 deletions
+9
View File
@@ -16,6 +16,8 @@
#include <stddef.h>
#include <string>
#include <openssl/rand.h>
namespace crypto {
@@ -28,4 +30,11 @@ void RandBytes(absl::Span<uint8_t> bytes) {
RandBytes(bytes.data(), bytes.size());
}
std::string RandBytes(size_t length) {
std::string result(length, 0);
RandBytes(const_cast<std::string::value_type *>(result.data()),
result.size());
return result;
}
} // namespace crypto