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

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

Issue 2888763006: Add a parser for messages with a Web Push Protocol-based payload (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 | « components/gcm_driver/crypto/BUILD.gn ('k') | components/gcm_driver/crypto/message_payload_parser.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/gcm_driver/crypto/gcm_message_cryptographer_unittest.cc
diff --git a/components/gcm_driver/crypto/gcm_message_cryptographer_unittest.cc b/components/gcm_driver/crypto/gcm_message_cryptographer_unittest.cc
index ea1c95f52f29107a12dbf0dc75f709c5d0dd9cd0..de85571c808710d6f244d6aec8c3c0666be98618 100644
--- a/components/gcm_driver/crypto/gcm_message_cryptographer_unittest.cc
+++ b/components/gcm_driver/crypto/gcm_message_cryptographer_unittest.cc
@@ -11,6 +11,7 @@
#include "base/memory/ptr_util.h"
#include "base/strings/string_piece.h"
#include "base/strings/string_util.h"
+#include "components/gcm_driver/crypto/message_payload_parser.h"
#include "components/gcm_driver/crypto/p256_key_util.h"
#include "crypto/random.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -23,7 +24,6 @@ namespace {
const char kExamplePlaintext[] = "Example plaintext";
// Expected sizes of the different input given to the cryptographer.
-constexpr size_t kUncompressedPointSize = 65;
constexpr size_t kEcdhSharedSecretSize = 32;
constexpr size_t kAuthSecretSize = 16;
constexpr size_t kSaltSize = 16;
@@ -866,45 +866,13 @@ TEST_F(GCMMessageCryptographerReferenceTest, ReferenceDraft08) {
base::Base64UrlDecodePolicy::IGNORE_PADDING,
&message));
- // TODO(peter): Break out the following in a separate message parser class so
- // that it can be reused by the GCMEncryptionProvider (on the receiving path)
- // and the gcm_crypto_test_helpers.cc file (on the sending path) too.
- //
- // The message contains a binary header in the following format:
- // [ salt(16) | record_size(4) | sender_public_key_len(1) |
- // sender_public_key(sender_public_key_len) ]
- //
- // For Web Push Encryption, which uses a P-256 sender key as uncompressed
- // P-256 EC points, the length of the sender key is 65 bytes, making the
- // total, fixed length of the header 86 bytes.
- //
- // The regular AEAD_AES_128_GCM ciphertext follows immediately after this. The
- // minimum overhead for a single record is 18 bytes. This means that an
- // incoming message must be at least 104 bytes in size.
- ASSERT_GE(message.size(), 104u);
-
- const char* current = &message.front();
-
- uint32_t record_size;
- uint8_t sender_public_key_length;
-
- base::StringPiece salt(current, kSaltSize);
- current += kSaltSize;
-
- base::ReadBigEndian(current, &record_size);
- current += sizeof(record_size);
-
- base::ReadBigEndian(current, &sender_public_key_length);
- current += sizeof(sender_public_key_length);
-
- ASSERT_EQ(sender_public_key_length, kUncompressedPointSize);
-
- base::StringPiece sender_public_key(current, sender_public_key_length);
- current += sender_public_key_length;
-
- base::StringPiece ciphertext(
- current, message.size() - kSaltSize - sizeof(record_size) -
- sizeof(sender_public_key_length) - sender_public_key_length);
+ MessagePayloadParser message_parser(message);
+ ASSERT_TRUE(message_parser.IsValid());
+
+ base::StringPiece salt = message_parser.salt();
+ uint32_t record_size = message_parser.record_size();
+ base::StringPiece sender_public_key = message_parser.public_key();
+ base::StringPiece ciphertext = message_parser.ciphertext();
std::string sender_shared_secret, receiver_shared_secret;
« no previous file with comments | « components/gcm_driver/crypto/BUILD.gn ('k') | components/gcm_driver/crypto/message_payload_parser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698