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

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

Issue 2671333004: Convert class-full-of-statics CryptoTestUtils into a namespace (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 f210e26b82116263d49f36ee75c4bfe0589ffccf..5b22e1ed9ebaf9a266b880e0099f8df6a96955a9 100644
--- a/net/quic/test_tools/crypto_test_utils.cc
+++ b/net/quic/test_tools/crypto_test_utils.cc
@@ -27,6 +27,7 @@
#include "net/quic/platform/api/quic_text_utils.h"
#include "net/quic/test_tools/quic_connection_peer.h"
#include "net/quic/test_tools/quic_framer_peer.h"
+#include "net/quic/test_tools/quic_stream_peer.h"
#include "net/quic/test_tools/quic_test_utils.h"
#include "net/quic/test_tools/simple_quic_framer.h"
#include "third_party/boringssl/src/include/openssl/bn.h"
@@ -41,6 +42,7 @@ using std::string;
namespace net {
namespace test {
+namespace crypto_test_utils {
namespace {
@@ -86,8 +88,7 @@ bool HexChar(char c, uint8_t* value) {
// A ChannelIDSource that works in asynchronous mode unless the |callback|
// argument to GetChannelIDKey is nullptr.
-class AsyncTestChannelIDSource : public ChannelIDSource,
- public CryptoTestUtils::CallbackSource {
+class AsyncTestChannelIDSource : public ChannelIDSource, public CallbackSource {
public:
// Takes ownership of |sync_source|, a synchronous ChannelIDSource.
explicit AsyncTestChannelIDSource(ChannelIDSource* sync_source)
@@ -260,14 +261,14 @@ class TestChannelIDSource : public ChannelIDSource {
} // anonymous namespace
-CryptoTestUtils::FakeServerOptions::FakeServerOptions() {}
+FakeServerOptions::FakeServerOptions() {}
-CryptoTestUtils::FakeServerOptions::~FakeServerOptions() {}
+FakeServerOptions::~FakeServerOptions() {}
-CryptoTestUtils::FakeClientOptions::FakeClientOptions()
+FakeClientOptions::FakeClientOptions()
: channel_id_enabled(false), channel_id_source_async(false) {}
-CryptoTestUtils::FakeClientOptions::~FakeClientOptions() {}
+FakeClientOptions::~FakeClientOptions() {}
namespace {
// This class is used by GenerateFullCHLO() to extract SCID and STK from
@@ -368,7 +369,7 @@ class FullChloGenerator {
*out_ = result_->client_hello;
out_->SetStringPiece(kSCID, scid);
out_->SetStringPiece(kSourceAddressTokenTag, srct);
- uint64_t xlct = CryptoTestUtils::LeafCertHashForTesting();
+ uint64_t xlct = LeafCertHashForTesting();
out_->SetValue(kXLCT, xlct);
}
@@ -388,14 +389,12 @@ class FullChloGenerator {
} // namespace
-// static
-int CryptoTestUtils::HandshakeWithFakeServer(
- QuicConfig* server_quic_config,
- MockQuicConnectionHelper* helper,
- MockAlarmFactory* alarm_factory,
- PacketSavingConnection* client_conn,
- QuicCryptoClientStream* client,
- const FakeServerOptions& options) {
+int HandshakeWithFakeServer(QuicConfig* server_quic_config,
+ MockQuicConnectionHelper* helper,
+ MockAlarmFactory* alarm_factory,
+ PacketSavingConnection* client_conn,
+ QuicCryptoClientStream* client,
+ const FakeServerOptions& options) {
PacketSavingConnection* server_conn =
new PacketSavingConnection(helper, alarm_factory, Perspective::IS_SERVER,
client_conn->supported_versions());
@@ -423,14 +422,12 @@ int CryptoTestUtils::HandshakeWithFakeServer(
return client->num_sent_client_hellos();
}
-// static
-int CryptoTestUtils::HandshakeWithFakeClient(
- MockQuicConnectionHelper* helper,
- MockAlarmFactory* alarm_factory,
- PacketSavingConnection* server_conn,
- QuicCryptoServerStream* server,
- const QuicServerId& server_id,
- const FakeClientOptions& options) {
+int HandshakeWithFakeClient(MockQuicConnectionHelper* helper,
+ MockAlarmFactory* alarm_factory,
+ PacketSavingConnection* server_conn,
+ QuicCryptoServerStream* server,
+ const QuicServerId& server_id,
+ const FakeClientOptions& options) {
PacketSavingConnection* client_conn =
new PacketSavingConnection(helper, alarm_factory, Perspective::IS_CLIENT);
// Advance the time, because timers do not like uninitialized times.
@@ -481,12 +478,10 @@ int CryptoTestUtils::HandshakeWithFakeClient(
return client_session.GetCryptoStream()->num_sent_client_hellos();
}
-// static
-void CryptoTestUtils::SetupCryptoServerConfigForTest(
- const QuicClock* clock,
- QuicRandom* rand,
- QuicCryptoServerConfig* crypto_config,
- const FakeServerOptions& fake_options) {
+void SetupCryptoServerConfigForTest(const QuicClock* clock,
+ QuicRandom* rand,
+ QuicCryptoServerConfig* crypto_config,
+ const FakeServerOptions& fake_options) {
QuicCryptoServerConfig::ConfigOptions options;
options.channel_id_enabled = true;
options.token_binding_params = fake_options.token_binding_params;
@@ -494,18 +489,15 @@ void CryptoTestUtils::SetupCryptoServerConfigForTest(
crypto_config->AddDefaultConfig(rand, clock, options));
}
-// static
-void CryptoTestUtils::CommunicateHandshakeMessages(
- PacketSavingConnection* client_conn,
- QuicCryptoStream* client,
- PacketSavingConnection* server_conn,
- QuicCryptoStream* server) {
+void CommunicateHandshakeMessages(PacketSavingConnection* client_conn,
+ QuicCryptoStream* client,
+ PacketSavingConnection* server_conn,
+ QuicCryptoStream* server) {
CommunicateHandshakeMessagesAndRunCallbacks(client_conn, client, server_conn,
server, nullptr);
}
-// static
-void CryptoTestUtils::CommunicateHandshakeMessagesAndRunCallbacks(
+void CommunicateHandshakeMessagesAndRunCallbacks(
PacketSavingConnection* client_conn,
QuicCryptoStream* client,
PacketSavingConnection* server_conn,
@@ -535,14 +527,12 @@ void CryptoTestUtils::CommunicateHandshakeMessagesAndRunCallbacks(
}
}
-// static
-std::pair<size_t, size_t> CryptoTestUtils::AdvanceHandshake(
- PacketSavingConnection* client_conn,
- QuicCryptoStream* client,
- size_t client_i,
- PacketSavingConnection* server_conn,
- QuicCryptoStream* server,
- size_t server_i) {
+std::pair<size_t, size_t> AdvanceHandshake(PacketSavingConnection* client_conn,
+ QuicCryptoStream* client,
+ size_t client_i,
+ PacketSavingConnection* server_conn,
+ QuicCryptoStream* server,
+ size_t server_i) {
QUIC_LOG(INFO) << "Processing "
<< client_conn->encrypted_packets_.size() - client_i
<< " packets client->server";
@@ -561,9 +551,7 @@ std::pair<size_t, size_t> CryptoTestUtils::AdvanceHandshake(
return std::make_pair(client_i, server_i);
}
-// static
-string CryptoTestUtils::GetValueForTag(const CryptoHandshakeMessage& message,
- QuicTag tag) {
+string GetValueForTag(const CryptoHandshakeMessage& message, QuicTag tag) {
QuicTagValueMap::const_iterator it = message.tag_value_map().find(tag);
if (it == message.tag_value_map().end()) {
return string();
@@ -571,12 +559,11 @@ string CryptoTestUtils::GetValueForTag(const CryptoHandshakeMessage& message,
return it->second;
}
-uint64_t CryptoTestUtils::LeafCertHashForTesting() {
+uint64_t LeafCertHashForTesting() {
QuicReferenceCountedPointer<ProofSource::Chain> chain;
QuicSocketAddress server_address;
QuicCryptoProof proof;
- std::unique_ptr<ProofSource> proof_source(
- CryptoTestUtils::ProofSourceForTesting());
+ std::unique_ptr<ProofSource> proof_source(ProofSourceForTesting());
if (!proof_source->GetProof(server_address, "", "",
AllSupportedVersions().front(), "",
QuicTagVector(), &chain, &proof) ||
@@ -641,15 +628,13 @@ class MockCommonCertSets : public CommonCertSets {
const uint32_t index_;
};
-CommonCertSets* CryptoTestUtils::MockCommonCertSets(StringPiece cert,
- uint64_t hash,
- uint32_t index) {
+CommonCertSets* MockCommonCertSets(StringPiece cert,
+ uint64_t hash,
+ uint32_t index) {
return new class MockCommonCertSets(cert, hash, index);
}
-// static
-void CryptoTestUtils::FillInDummyReject(CryptoHandshakeMessage* rej,
- bool reject_is_stateless) {
+void FillInDummyReject(CryptoHandshakeMessage* rej, bool reject_is_stateless) {
if (reject_is_stateless) {
rej->set_tag(kSREJ);
} else {
@@ -683,29 +668,28 @@ void CryptoTestUtils::FillInDummyReject(CryptoHandshakeMessage* rej,
rej->SetVector(kRREJ, reject_reasons);
}
-void CryptoTestUtils::CompareClientAndServerKeys(
- QuicCryptoClientStream* client,
- QuicCryptoServerStream* server) {
- QuicFramer* client_framer =
- QuicConnectionPeer::GetFramer(client->session()->connection());
- QuicFramer* server_framer =
- QuicConnectionPeer::GetFramer(server->session()->connection());
+void CompareClientAndServerKeys(QuicCryptoClientStream* client,
+ QuicCryptoServerStream* server) {
+ QuicFramer* client_framer = QuicConnectionPeer::GetFramer(
+ QuicStreamPeer::session(client)->connection());
+ QuicFramer* server_framer = QuicConnectionPeer::GetFramer(
+ QuicStreamPeer::session(server)->connection());
const QuicEncrypter* client_encrypter(
QuicFramerPeer::GetEncrypter(client_framer, ENCRYPTION_INITIAL));
const QuicDecrypter* client_decrypter(
- client->session()->connection()->decrypter());
+ QuicStreamPeer::session(client)->connection()->decrypter());
const QuicEncrypter* client_forward_secure_encrypter(
QuicFramerPeer::GetEncrypter(client_framer, ENCRYPTION_FORWARD_SECURE));
const QuicDecrypter* client_forward_secure_decrypter(
- client->session()->connection()->alternative_decrypter());
+ QuicStreamPeer::session(client)->connection()->alternative_decrypter());
const QuicEncrypter* server_encrypter(
QuicFramerPeer::GetEncrypter(server_framer, ENCRYPTION_INITIAL));
const QuicDecrypter* server_decrypter(
- server->session()->connection()->decrypter());
+ QuicStreamPeer::session(server)->connection()->decrypter());
const QuicEncrypter* server_forward_secure_encrypter(
QuicFramerPeer::GetEncrypter(server_framer, ENCRYPTION_FORWARD_SECURE));
const QuicDecrypter* server_forward_secure_decrypter(
- server->session()->connection()->alternative_decrypter());
+ QuicStreamPeer::session(server)->connection()->alternative_decrypter());
StringPiece client_encrypter_key = client_encrypter->GetKey();
StringPiece client_encrypter_iv = client_encrypter->GetNoncePrefix();
@@ -803,8 +787,7 @@ void CryptoTestUtils::CompareClientAndServerKeys(
server_tb_ekm.data(), server_tb_ekm.length());
}
-// static
-QuicTag CryptoTestUtils::ParseTag(const char* tagstr) {
+QuicTag ParseTag(const char* tagstr) {
const size_t len = strlen(tagstr);
CHECK_NE(0u, len);
@@ -836,8 +819,7 @@ QuicTag CryptoTestUtils::ParseTag(const char* tagstr) {
return tag;
}
-// static
-CryptoHandshakeMessage CryptoTestUtils::Message(const char* message_tag, ...) {
+CryptoHandshakeMessage Message(const char* message_tag, ...) {
va_list ap;
va_start(ap, message_tag);
@@ -901,17 +883,15 @@ CryptoHandshakeMessage CryptoTestUtils::Message(const char* message_tag, ...) {
return *parsed;
}
-// static
-ChannelIDSource* CryptoTestUtils::ChannelIDSourceForTesting() {
+ChannelIDSource* ChannelIDSourceForTesting() {
return new TestChannelIDSource();
}
-// static
-void CryptoTestUtils::MovePackets(PacketSavingConnection* source_conn,
- size_t* inout_packet_index,
- QuicCryptoStream* dest_stream,
- PacketSavingConnection* dest_conn,
- Perspective dest_perspective) {
+void MovePackets(PacketSavingConnection* source_conn,
+ size_t* inout_packet_index,
+ QuicCryptoStream* dest_stream,
+ PacketSavingConnection* dest_conn,
+ Perspective dest_perspective) {
SimpleQuicFramer framer(source_conn->supported_versions(), dest_perspective);
CryptoFramer crypto_framer;
CryptoFramerVisitor crypto_visitor;
@@ -953,18 +933,18 @@ void CryptoTestUtils::MovePackets(PacketSavingConnection* source_conn,
QuicConnectionPeer::SetCurrentPacket(dest_conn, StringPiece(nullptr, 0));
}
-CryptoHandshakeMessage CryptoTestUtils::GenerateDefaultInchoateCHLO(
+CryptoHandshakeMessage GenerateDefaultInchoateCHLO(
const QuicClock* clock,
QuicVersion version,
QuicCryptoServerConfig* crypto_config) {
// clang-format off
- return CryptoTestUtils::Message(
+ return Message(
"CHLO",
"PDMD", "X509",
"AEAD", "AESG",
"KEXS", "C255",
- "PUBS", CryptoTestUtils::GenerateClientPublicValuesHex().c_str(),
- "NONC", CryptoTestUtils::GenerateClientNonceHex(clock,
+ "PUBS", GenerateClientPublicValuesHex().c_str(),
+ "NONC", GenerateClientNonceHex(clock,
crypto_config).c_str(),
"VER\0", QuicTagToString(
QuicVersionToQuicTag(version)).c_str(),
@@ -973,9 +953,8 @@ CryptoHandshakeMessage CryptoTestUtils::GenerateDefaultInchoateCHLO(
// clang-format on
}
-string CryptoTestUtils::GenerateClientNonceHex(
- const QuicClock* clock,
- QuicCryptoServerConfig* crypto_config) {
+string GenerateClientNonceHex(const QuicClock* clock,
+ QuicCryptoServerConfig* crypto_config) {
net::QuicCryptoServerConfig::ConfigOptions old_config_options;
net::QuicCryptoServerConfig::ConfigOptions new_config_options;
old_config_options.id = "old-config-id";
@@ -998,23 +977,21 @@ string CryptoTestUtils::GenerateClientNonceHex(
return ("#" + QuicTextUtils::HexEncode(nonce));
}
-string CryptoTestUtils::GenerateClientPublicValuesHex() {
+string GenerateClientPublicValuesHex() {
char public_value[32];
memset(public_value, 42, sizeof(public_value));
return ("#" + QuicTextUtils::HexEncode(public_value, sizeof(public_value)));
}
-// static
-void CryptoTestUtils::GenerateFullCHLO(
- const CryptoHandshakeMessage& inchoate_chlo,
- QuicCryptoServerConfig* crypto_config,
- QuicSocketAddress server_addr,
- QuicSocketAddress client_addr,
- QuicVersion version,
- const QuicClock* clock,
- QuicReferenceCountedPointer<QuicSignedServerConfig> proof,
- QuicCompressedCertsCache* compressed_certs_cache,
- CryptoHandshakeMessage* out) {
+void GenerateFullCHLO(const CryptoHandshakeMessage& inchoate_chlo,
+ QuicCryptoServerConfig* crypto_config,
+ QuicSocketAddress server_addr,
+ QuicSocketAddress client_addr,
+ QuicVersion version,
+ const QuicClock* clock,
+ QuicReferenceCountedPointer<QuicSignedServerConfig> proof,
+ QuicCompressedCertsCache* compressed_certs_cache,
+ CryptoHandshakeMessage* out) {
// Pass a inchoate CHLO.
FullChloGenerator generator(crypto_config, server_addr, client_addr, clock,
proof, compressed_certs_cache, out);
@@ -1023,5 +1000,6 @@ void CryptoTestUtils::GenerateFullCHLO(
generator.GetValidateClientHelloCallback());
}
+} // namespace crypto_test_utils
} // namespace test
} // namespace net
« 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