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

Unified Diff: net/quic/test_tools/crypto_test_utils.cc

Issue 2678973002: Replace va_arg version of crypto_test_utils::Message with a more modern vector argument version. (Closed)
Patch Set: Created 3 years, 10 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 | « net/quic/test_tools/crypto_test_utils.h ('k') | net/quic/test_tools/crypto_test_utils_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/quic/test_tools/crypto_test_utils.cc
diff --git a/net/quic/test_tools/crypto_test_utils.cc b/net/quic/test_tools/crypto_test_utils.cc
index 92c563187c1fa6b10b22320151085da7e951b430..1280dd3a6cd583e783002bb10c3b9e5a9e7c89d5 100644
--- a/net/quic/test_tools/crypto_test_utils.cc
+++ b/net/quic/test_tools/crypto_test_utils.cc
@@ -841,57 +841,35 @@ QuicTag ParseTag(const char* tagstr) {
return tag;
}
-CryptoHandshakeMessage Message(const char* message_tag, ...) {
- va_list ap;
- va_start(ap, message_tag);
+CryptoHandshakeMessage CreateCHLO(
+ std::vector<std::pair<string, string>> tags_and_values) {
+ return CreateCHLO(tags_and_values, -1);
+}
+CryptoHandshakeMessage CreateCHLO(
+ std::vector<std::pair<string, string>> tags_and_values,
+ int minimum_size_bytes) {
CryptoHandshakeMessage msg;
- msg.set_tag(ParseTag(message_tag));
-
- for (;;) {
- const char* tagstr = va_arg(ap, const char*);
- if (tagstr == nullptr) {
- break;
- }
+ msg.set_tag(MakeQuicTag('C', 'H', 'L', 'O'));
- if (tagstr[0] == '$') {
- // Special value.
- const char* const special = tagstr + 1;
- if (strcmp(special, "padding") == 0) {
- const int min_bytes = va_arg(ap, int);
- msg.set_minimum_size(min_bytes);
- } else {
- CHECK(false) << "Unknown special value: " << special;
- }
-
- continue;
- }
-
- const QuicTag tag = ParseTag(tagstr);
- const char* valuestr = va_arg(ap, const char*);
-
- size_t len = strlen(valuestr);
- if (len > 0 && valuestr[0] == '#') {
- valuestr++;
- len--;
+ if (minimum_size_bytes > 0) {
+ msg.set_minimum_size(minimum_size_bytes);
+ }
- CHECK_EQ(0u, len % 2);
- std::unique_ptr<uint8_t[]> buf(new uint8_t[len / 2]);
+ for (const auto& tag_and_value : tags_and_values) {
+ const string& tag = tag_and_value.first;
+ const string& value = tag_and_value.second;
- for (size_t i = 0; i < len / 2; i++) {
- uint8_t v = 0;
- CHECK(HexChar(valuestr[i * 2], &v));
- buf[i] = v << 4;
- CHECK(HexChar(valuestr[i * 2 + 1], &v));
- buf[i] |= v;
- }
+ const QuicTag quic_tag = ParseTag(tag.c_str());
- msg.SetStringPiece(
- tag, StringPiece(reinterpret_cast<char*>(buf.get()), len / 2));
+ size_t value_len = value.length();
+ if (value_len > 0 && value[0] == '#') {
+ // This is ascii encoded hex.
+ string hex_value = QuicTextUtils::HexDecode(StringPiece(&value[1]));
+ msg.SetStringPiece(quic_tag, hex_value);
continue;
}
-
- msg.SetStringPiece(tag, valuestr);
+ msg.SetStringPiece(quic_tag, value);
}
// The CryptoHandshakeMessage needs to be serialized and parsed to ensure
@@ -901,7 +879,6 @@ CryptoHandshakeMessage Message(const char* message_tag, ...) {
CryptoFramer::ParseMessage(bytes->AsStringPiece()));
CHECK(parsed.get());
- va_end(ap);
return *parsed;
}
@@ -960,18 +937,14 @@ CryptoHandshakeMessage GenerateDefaultInchoateCHLO(
QuicVersion version,
QuicCryptoServerConfig* crypto_config) {
// clang-format off
- return Message(
- "CHLO",
- "PDMD", "X509",
- "AEAD", "AESG",
- "KEXS", "C255",
- "PUBS", GenerateClientPublicValuesHex().c_str(),
- "NONC", GenerateClientNonceHex(clock,
- crypto_config).c_str(),
- "VER\0", QuicTagToString(
- QuicVersionToQuicTag(version)).c_str(),
- "$padding", static_cast<int>(kClientHelloMinimumSize),
- nullptr);
+ return CreateCHLO(
+ {{"PDMD", "X509"},
+ {"AEAD", "AESG"},
+ {"KEXS", "C255"},
+ {"PUBS", GenerateClientPublicValuesHex().c_str()},
+ {"NONC", GenerateClientNonceHex(clock, crypto_config).c_str()},
+ {"VER\0", QuicTagToString(QuicVersionToQuicTag(version)).c_str()}},
+ kClientHelloMinimumSize);
// clang-format on
}
« no previous file with comments | « net/quic/test_tools/crypto_test_utils.h ('k') | net/quic/test_tools/crypto_test_utils_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698