• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2015 The Android Open Source Project
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //      http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef KEYSTORE_KEYSTORE_CLIENT_MOCK_H_
16 #define KEYSTORE_KEYSTORE_CLIENT_MOCK_H_
17 
18 #include "gmock/gmock.h"
19 #include "keystore/keystore_client.h"
20 
21 using testing::_;
22 
23 namespace keystore {
24 
25 // A mock implementation of KeystoreClient. By default all methods do nothing
26 // and return KM_ERROR_OK (or false).
27 class KeystoreClientMock : public KeystoreClient {
28   public:
29     KeystoreClientMock() = default;
30     ~KeystoreClientMock() = default;
31 
32     MOCK_METHOD3(encryptWithAuthentication,
33                  bool(const std::string& key_name, const std::string& data,
34                       std::string* encrypted_data));
35     MOCK_METHOD3(decryptWithAuthentication,
36                  bool(const std::string& key_name, const std::string& encrypted_data,
37                       std::string* data));
38     MOCK_METHOD7(oneShotOperation,
39                  bool(keymaster_purpose_t purpose, const std::string& key_name,
40                       const keymaster::AuthorizationSet& input_parameters,
41                       const std::string& input_data, const std::string& signature_to_verify,
42                       keymaster::AuthorizationSet* output_parameters, std::string* output_data));
43     MOCK_METHOD1(addRandomNumberGeneratorEntropy, int32_t(const std::string& entropy));
44     MOCK_METHOD4(generateKey,
45                  int32_t(const std::string& key_name,
46                          const keymaster::AuthorizationSet& key_parameters,
47                          keymaster::AuthorizationSet* hardware_enforced_characteristics,
48                          keymaster::AuthorizationSet* software_enforced_characteristics));
49     MOCK_METHOD3(getKeyCharacteristics,
50                  int32_t(const std::string& key_name,
51                          keymaster::AuthorizationSet* hardware_enforced_characteristics,
52                          keymaster::AuthorizationSet* software_enforced_characteristics));
53     MOCK_METHOD6(importKey,
54                  int32_t(const std::string& key_name,
55                          const keymaster::AuthorizationSet& key_parameters,
56                          keymaster_key_format_t key_format, const std::string& key_data,
57                          keymaster::AuthorizationSet* hardware_enforced_characteristics,
58                          keymaster::AuthorizationSet* software_enforced_characteristics));
59     MOCK_METHOD3(exportKey, int32_t(keymaster_key_format_t export_format,
60                                     const std::string& key_name, std::string* export_data));
61     MOCK_METHOD1(deleteKey, int32_t(const std::string& key_name));
62     MOCK_METHOD0(deleteAllKeys, int32_t());
63     MOCK_METHOD5(beginOperation, int32_t(keymaster_purpose_t purpose, const std::string& key_name,
64                                          const keymaster::AuthorizationSet& input_parameters,
65                                          keymaster::AuthorizationSet* output_parameters,
66                                          keymaster_operation_handle_t* handle));
67     MOCK_METHOD6(updateOperation,
68                  int32_t(keymaster_operation_handle_t handle,
69                          const keymaster::AuthorizationSet& input_parameters,
70                          const std::string& input_data, size_t* num_input_bytes_consumed,
71                          keymaster::AuthorizationSet* output_parameters, std::string* output_data));
72     MOCK_METHOD5(finishOperation,
73                  int32_t(keymaster_operation_handle_t handle,
74                          const keymaster::AuthorizationSet& input_parameters,
75                          const std::string& signature_to_verify,
76                          keymaster::AuthorizationSet* output_parameters, std::string* output_data));
77     MOCK_METHOD1(abortOperation, int32_t(keymaster_operation_handle_t handle));
78     MOCK_METHOD1(doesKeyExist, bool(const std::string& key_name));
79     MOCK_METHOD2(listKeys,
80                  bool(const std::string& prefix, std::vector<std::string>* key_name_list));
81 
82   private:
83     DISALLOW_COPY_AND_ASSIGN(KeystoreClientMock);
84 };
85 
86 }  // namespace keystore
87 
88 #endif  // KEYSTORE_KEYSTORE_CLIENT_MOCK_H_
89