Switch to absl random to generate payload and attachment ids.

PiperOrigin-RevId: 638749436
This commit is contained in:
Francis Tsui
2024-05-30 12:44:55 -07:00
committed by Copybara-Service
parent 7459330bd5
commit aa277cc202
3 changed files with 12 additions and 11 deletions
+2 -2
View File
@@ -21,8 +21,8 @@ cc_library(
"//internal/base:files",
"//internal/crypto_cros",
"//internal/interop:authentication_status",
"//internal/platform:types",
"//sharing/common:compatible_u8_string",
"@com_google_absl//absl/random",
"@com_google_absl//absl/strings:string_view",
"@com_google_absl//absl/time",
],
@@ -60,7 +60,6 @@ cc_library(
":connection_types",
"//internal/crypto_cros",
"//internal/network:url",
"//internal/platform:types",
"//sharing/common:compatible_u8_string",
"//sharing/common:enum",
"//sharing/internal/base",
@@ -68,6 +67,7 @@ cc_library(
"//sharing/proto:enums_cc_proto",
"//sharing/proto:wire_format_cc_proto",
"@com_google_absl//absl/container:flat_hash_set",
"@com_google_absl//absl/random",
"@com_google_absl//absl/status:statusor",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/strings:str_format",
+5 -5
View File
@@ -14,18 +14,18 @@
#include "sharing/attachment.h"
#include <stdint.h>
#include <cstdint>
#include <limits>
#include "internal/platform/crypto.h"
#include "absl/random/random.h"
namespace nearby {
namespace sharing {
namespace {
int64_t CreateRandomId() {
int64_t id;
RandBytes(&id, sizeof(id));
return id;
absl::BitGen gen;
return absl::Uniform<int64_t>(gen, 1, std::numeric_limits<int64_t>::max());
}
} // namespace
+5 -4
View File
@@ -19,16 +19,17 @@
#include <filesystem> // NOLINT(build/c++17)
#include <functional>
#include <limits>
#include <optional>
#include <string>
#include <utility>
#include <vector>
#include "absl/random/random.h"
#include "absl/strings/string_view.h"
#include "absl/time/time.h"
#include "internal/base/files.h"
#include "internal/interop/authentication_status.h"
#include "internal/platform/crypto.h"
#include "sharing/common/compatible_u8_string.h"
namespace nearby {
@@ -476,9 +477,9 @@ struct Payload {
: Payload(GenerateId(), std::vector<uint8_t>(bytes, bytes + size)) {}
int64_t GenerateId() {
int64_t id;
RandBytes(&id, sizeof(id));
return id;
absl::BitGen bitgen;
return absl::Uniform<int64_t>(absl::IntervalOpenClosed, bitgen, 0,
std::numeric_limits<int64_t>::max());
}
};