Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / net / quic / test_tools / crypto_test_utils_nss.cc
blob946b05318249eb2df0a213a8bebe34100af98e8b
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "net/quic/test_tools/crypto_test_utils.h"
7 #include "base/stl_util.h"
8 #include "base/strings/string_util.h"
9 #include "crypto/ec_private_key.h"
10 #include "crypto/ec_signature_creator.h"
11 #include "net/quic/crypto/channel_id.h"
12 #include "net/quic/crypto/channel_id_chromium.h"
14 using base::StringPiece;
15 using std::string;
17 namespace net {
19 namespace test {
21 class TestChannelIDSource : public ChannelIDSource {
22 public:
23 ~TestChannelIDSource() override { STLDeleteValues(&hostname_to_key_); }
25 // ChannelIDSource implementation.
27 QuicAsyncStatus GetChannelIDKey(
28 const string& hostname,
29 scoped_ptr<ChannelIDKey>* channel_id_key,
30 ChannelIDSourceCallback* /*callback*/) override {
31 channel_id_key->reset(new ChannelIDKeyChromium(HostnameToKey(hostname)));
32 return QUIC_SUCCESS;
35 private:
36 typedef std::map<string, crypto::ECPrivateKey*> HostnameToKeyMap;
38 scoped_ptr<crypto::ECPrivateKey> HostnameToKey(const string& hostname) {
39 HostnameToKeyMap::const_iterator it = hostname_to_key_.find(hostname);
40 if (it != hostname_to_key_.end()) {
41 return make_scoped_ptr(it->second->Copy());
44 crypto::ECPrivateKey* keypair = crypto::ECPrivateKey::Create();
45 if (!keypair) {
46 return nullptr;
48 hostname_to_key_[hostname] = keypair;
49 return make_scoped_ptr(keypair->Copy());
52 HostnameToKeyMap hostname_to_key_;
55 // static
56 ChannelIDSource* CryptoTestUtils::ChannelIDSourceForTesting() {
57 return new TestChannelIDSource();
60 } // namespace test
62 } // namespace net