Roll forward to cl/314747126

Signed-off-by: Alexey Polyudov <apolyudov@google.com>
Change-Id: Ie19e006429b138b3768e97dae971a43fdc5ef8bf
This commit is contained in:
Alexey Polyudov
2020-06-04 13:50:45 -07:00
parent de31c27947
commit 4baa1ce96a
365 changed files with 28586 additions and 1503 deletions
+22
View File
@@ -14,9 +14,11 @@
#include "core/internal/mediums/utils.h"
#include <cstdint>
#include <sstream>
#include "platform/exception.h"
#include "platform/prng.h"
#include "absl/strings/escaping.h"
namespace location {
@@ -62,6 +64,26 @@ ConstPtr<ByteArray> Utils::legacySha256HashOnlyForPrinting(
return Utils::sha256Hash(hash_utils, formatted_hex_byte_array.get(), length);
}
ConstPtr<ByteArray> Utils::generateRandomBytes(size_t length) {
Prng rng;
std::string data;
data.reserve(length);
// Adds 4 random bytes per iteration.
while (length > 0) {
std::uint32_t val = rng.nextUInt32();
for (int i = 0; i < 4; i++) {
data += val & 0xFF;
val >>= 8;
length--;
if (!length) break;
}
}
return MakeConstPtr(new ByteArray(data));
}
std::string Utils::bytesToPrintableHexString(ConstPtr<ByteArray> bytes) {
std::string hex_string(
absl::BytesToHexString(std::string(bytes->getData(), bytes->size())));