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

Unified Diff: components/gcm_driver/crypto/gcm_message_cryptographer.cc

Issue 2901923002: Reduce string building complexity when needing to add a NUL byte (Closed)
Patch Set: rebase Created 3 years, 7 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/gcm_driver/crypto/gcm_message_cryptographer.cc
diff --git a/components/gcm_driver/crypto/gcm_message_cryptographer.cc b/components/gcm_driver/crypto/gcm_message_cryptographer.cc
index deaaba33a50f9981729e08e219c3aec98434e3b9..fb72d73dcfb303707a2142d2d9ba1efd98676179 100644
--- a/components/gcm_driver/crypto/gcm_message_cryptographer.cc
+++ b/components/gcm_driver/crypto/gcm_message_cryptographer.cc
@@ -57,10 +57,8 @@ class WebPushEncryptionDraft03
const base::StringPiece& auth_secret) override {
const char kInfo[] = "Content-Encoding: auth";
- std::string info;
- info.reserve(sizeof(kInfo) + 1);
- info.append(kInfo);
- info.append(1, '\0');
+ // This deliberately copies over the NUL terminus.
+ base::StringPiece info(kInfo, sizeof(kInfo));
crypto::HKDF hkdf(ecdh_shared_secret, auth_secret, info,
32, /* key_bytes_to_generate */
@@ -197,9 +195,10 @@ class WebPushEncryptionDraft08
const char kInfo[] = "WebPush: info";
std::string info;
- info.reserve(sizeof(kInfo) + 1 + 65 + 65);
- info.append(kInfo);
- info.append(1, '\0');
+ info.reserve(sizeof(kInfo) + 65 + 65);
+
+ // This deliberately copies over the NUL terminus.
+ info.append(kInfo, sizeof(kInfo));
recipient_public_key.AppendToString(&info);
sender_public_key.AppendToString(&info);
« 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