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
;
21 class TestChannelIDSource
: public ChannelIDSource
{
23 virtual ~TestChannelIDSource() {
24 STLDeleteValues(&hostname_to_key_
);
27 // ChannelIDSource implementation.
29 virtual QuicAsyncStatus
GetChannelIDKey(
30 const string
& hostname
,
31 scoped_ptr
<ChannelIDKey
>* channel_id_key
,
32 ChannelIDSourceCallback
* /*callback*/) OVERRIDE
{
33 channel_id_key
->reset(new ChannelIDKeyChromium(HostnameToKey(hostname
)));
38 typedef std::map
<string
, crypto::ECPrivateKey
*> HostnameToKeyMap
;
40 crypto::ECPrivateKey
* HostnameToKey(const string
& hostname
) {
41 HostnameToKeyMap::const_iterator it
= hostname_to_key_
.find(hostname
);
42 if (it
!= hostname_to_key_
.end()) {
43 return it
->second
->Copy();
46 crypto::ECPrivateKey
* keypair
= crypto::ECPrivateKey::Create();
50 hostname_to_key_
[hostname
] = keypair
;
51 return keypair
->Copy();
54 HostnameToKeyMap hostname_to_key_
;
58 ChannelIDSource
* CryptoTestUtils::ChannelIDSourceForTesting() {
59 return new TestChannelIDSource();