[email protected] | 3798a56a | 2012-08-30 09:03:46 | [diff] [blame] | 1 | // Copyright (c) 2012 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. | ||||
4 | |||||
ygorshenin | 39e3678 | 2014-08-29 13:09:51 | [diff] [blame] | 5 | #ifndef COMPONENTS_OWNERSHIP_MOCK_OWNER_KEY_UTIL_H_ |
6 | #define COMPONENTS_OWNERSHIP_MOCK_OWNER_KEY_UTIL_H_ | ||||
[email protected] | 3798a56a | 2012-08-30 09:03:46 | [diff] [blame] | 7 | |
8 | #include <vector> | ||||
9 | |||||
10 | #include "base/basictypes.h" | ||||
11 | #include "base/compiler_specific.h" | ||||
[email protected] | 5799981 | 2013-02-24 05:40:52 | [diff] [blame] | 12 | #include "base/files/file_path.h" |
[email protected] | 3798a56a | 2012-08-30 09:03:46 | [diff] [blame] | 13 | #include "base/memory/scoped_ptr.h" |
ygorshenin | 39e3678 | 2014-08-29 13:09:51 | [diff] [blame] | 14 | #include "components/ownership/owner_key_util.h" |
15 | #include "components/ownership/ownership_export.h" | ||||
[email protected] | 3798a56a | 2012-08-30 09:03:46 | [diff] [blame] | 16 | |
ygorshenin | 39e3678 | 2014-08-29 13:09:51 | [diff] [blame] | 17 | namespace ownership { |
[email protected] | 3798a56a | 2012-08-30 09:03:46 | [diff] [blame] | 18 | |
ygorshenin | 39e3678 | 2014-08-29 13:09:51 | [diff] [blame] | 19 | // Implementation of OwnerKeyUtil which should be used only for |
20 | // testing. | ||||
21 | class OWNERSHIP_EXPORT MockOwnerKeyUtil : public OwnerKeyUtil { | ||||
[email protected] | 3798a56a | 2012-08-30 09:03:46 | [diff] [blame] | 22 | public: |
23 | MockOwnerKeyUtil(); | ||||
24 | |||||
ygorshenin | 39e3678 | 2014-08-29 13:09:51 | [diff] [blame] | 25 | // OwnerKeyUtil implementation: |
mostynb | fe59f48 | 2014-10-06 15:04:46 | [diff] [blame] | 26 | virtual bool ImportPublicKey(std::vector<uint8>* output) override; |
ygorshenin | 39e3678 | 2014-08-29 13:09:51 | [diff] [blame] | 27 | #if defined(USE_NSS) |
[email protected] | 196e53e8 | 2014-05-21 01:50:25 | [diff] [blame] | 28 | virtual crypto::RSAPrivateKey* FindPrivateKeyInSlot( |
29 | const std::vector<uint8>& key, | ||||
mostynb | fe59f48 | 2014-10-06 15:04:46 | [diff] [blame] | 30 | PK11SlotInfo* slot) override; |
ygorshenin | 39e3678 | 2014-08-29 13:09:51 | [diff] [blame] | 31 | #endif // defined(USE_NSS) |
mostynb | fe59f48 | 2014-10-06 15:04:46 | [diff] [blame] | 32 | virtual bool IsPublicKeyPresent() override; |
[email protected] | 3798a56a | 2012-08-30 09:03:46 | [diff] [blame] | 33 | |
[email protected] | 7452c1c | 2012-11-23 18:44:59 | [diff] [blame] | 34 | // Clears the public and private keys. |
35 | void Clear(); | ||||
36 | |||||
[email protected] | 3798a56a | 2012-08-30 09:03:46 | [diff] [blame] | 37 | // Configures the mock to return the given public key. |
38 | void SetPublicKey(const std::vector<uint8>& key); | ||||
39 | |||||
40 | // Sets the public key to use from the given private key, but doesn't | ||||
41 | // configure the private key. | ||||
[email protected] | 4e8c49a | 2013-08-05 22:02:07 | [diff] [blame] | 42 | void SetPublicKeyFromPrivateKey(const crypto::RSAPrivateKey& key); |
[email protected] | 3798a56a | 2012-08-30 09:03:46 | [diff] [blame] | 43 | |
44 | // Sets the private key (also configures the public key). | ||||
[email protected] | 4e8c49a | 2013-08-05 22:02:07 | [diff] [blame] | 45 | void SetPrivateKey(scoped_ptr<crypto::RSAPrivateKey> key); |
[email protected] | 3798a56a | 2012-08-30 09:03:46 | [diff] [blame] | 46 | |
ygorshenin | 39e3678 | 2014-08-29 13:09:51 | [diff] [blame] | 47 | private: |
[email protected] | 3798a56a | 2012-08-30 09:03:46 | [diff] [blame] | 48 | virtual ~MockOwnerKeyUtil(); |
49 | |||||
[email protected] | 3798a56a | 2012-08-30 09:03:46 | [diff] [blame] | 50 | std::vector<uint8> public_key_; |
51 | scoped_ptr<crypto::RSAPrivateKey> private_key_; | ||||
52 | |||||
53 | DISALLOW_COPY_AND_ASSIGN(MockOwnerKeyUtil); | ||||
54 | }; | ||||
55 | |||||
ygorshenin | 39e3678 | 2014-08-29 13:09:51 | [diff] [blame] | 56 | } // namespace ownership |
[email protected] | 3798a56a | 2012-08-30 09:03:46 | [diff] [blame] | 57 | |
ygorshenin | 39e3678 | 2014-08-29 13:09:51 | [diff] [blame] | 58 | #endif // COMPONENTS_OWNERSHIP_MOCK_OWNER_KEY_UTIL_H_ |