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