Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(24)

Unified Diff: components/sync/engine_impl/commit.cc

Issue 2637173004: [Sync] Do not use base::RandBytesAsString to generate random string (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/sync/engine_impl/commit.cc
diff --git a/components/sync/engine_impl/commit.cc b/components/sync/engine_impl/commit.cc
index 877ba4ca07983cf5524449ee07669a1ca2a81059..b46d1c3a4dfcc928b6f543b6031a27bca8d753a2 100644
--- a/components/sync/engine_impl/commit.cc
+++ b/components/sync/engine_impl/commit.cc
@@ -27,8 +27,29 @@ namespace {
// because it is not too large (to hurt performance and compression ratio), but
// it is not too small to easily be canceled out using statistical analysis.
const size_t kPaddingSize = 256;
+
+const char kLegalCharacters[] =
+ "abcdefghijklmnopqrstuvwxyz"
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ "0123456789"
+ " .-,/\\:;";
+
+const int first_char_index = 0;
+const int last_char_index = sizeof(kLegalCharacters) - 2;
+
+std::string RandomString(int length) {
maxbogue 2017/01/20 01:24:56 I was poking around trying to understand RandInt a
Gang Wu 2017/01/20 07:46:56 Done.
+ std::string random;
+ random.reserve(length);
+ for (int i = 0; i < length; ++i) {
+ random.push_back(
+ kLegalCharacters[base::RandInt(first_char_index, last_char_index)]);
+ }
+
+ return random;
}
+} // namespace
+
Commit::Commit(ContributionMap contributions,
const sync_pb::ClientToServerMessage& message,
ExtensionsActivity::Records extensions_activity_buffer)
@@ -69,7 +90,7 @@ Commit* Commit::Init(ModelTypeSet requested_types,
// Set padding to mitigate CRIME attack.
if (base::FeatureList::IsEnabled(syncer::kSyncClientToServerCompression)) {
- commit_message->set_padding(base::RandBytesAsString(kPaddingSize));
+ commit_message->set_padding(RandomString(kPaddingSize));
}
// Set extensions activity if bookmark commits are present.
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698