1//
2// Copyright (C) 2014 The Android Open Source Project
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8//      http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15//
16
17#ifndef TRUNKS_MOCK_TPM_UTILITY_H_
18#define TRUNKS_MOCK_TPM_UTILITY_H_
19
20#include <string>
21
22#include <gmock/gmock.h>
23
24#include "trunks/tpm_utility.h"
25
26namespace trunks {
27
28class MockTpmUtility : public TpmUtility {
29 public:
30  MockTpmUtility();
31  ~MockTpmUtility() override;
32
33  MOCK_METHOD0(Startup, TPM_RC());
34  MOCK_METHOD0(Clear, TPM_RC());
35  MOCK_METHOD0(Shutdown, void());
36  MOCK_METHOD0(InitializeTpm, TPM_RC());
37  MOCK_METHOD1(AllocatePCR, TPM_RC(const std::string&));
38  MOCK_METHOD3(TakeOwnership,
39               TPM_RC(const std::string&,
40                      const std::string&,
41                      const std::string&));
42  MOCK_METHOD2(StirRandom, TPM_RC(const std::string&, AuthorizationDelegate*));
43  MOCK_METHOD3(GenerateRandom,
44               TPM_RC(size_t, AuthorizationDelegate*, std::string*));
45  MOCK_METHOD3(ExtendPCR,
46               TPM_RC(int, const std::string&, AuthorizationDelegate*));
47  MOCK_METHOD2(ReadPCR, TPM_RC(int, std::string*));
48  MOCK_METHOD6(AsymmetricEncrypt,
49               TPM_RC(TPM_HANDLE,
50                      TPM_ALG_ID,
51                      TPM_ALG_ID,
52                      const std::string&,
53                      AuthorizationDelegate*,
54                      std::string*));
55  MOCK_METHOD6(AsymmetricDecrypt,
56               TPM_RC(TPM_HANDLE,
57                      TPM_ALG_ID,
58                      TPM_ALG_ID,
59                      const std::string&,
60                      AuthorizationDelegate*,
61                      std::string*));
62  MOCK_METHOD6(Sign,
63               TPM_RC(TPM_HANDLE,
64                      TPM_ALG_ID,
65                      TPM_ALG_ID,
66                      const std::string&,
67                      AuthorizationDelegate*,
68                      std::string*));
69  MOCK_METHOD6(Verify,
70               TPM_RC(TPM_HANDLE,
71                      TPM_ALG_ID,
72                      TPM_ALG_ID,
73                      const std::string&,
74                      const std::string&,
75                      AuthorizationDelegate*));
76  MOCK_METHOD2(CertifyCreation, TPM_RC(TPM_HANDLE, const std::string&));
77  MOCK_METHOD4(ChangeKeyAuthorizationData,
78               TPM_RC(TPM_HANDLE,
79                      const std::string&,
80                      AuthorizationDelegate*,
81                      std::string*));
82  MOCK_METHOD7(ImportRSAKey,
83               TPM_RC(AsymmetricKeyUsage,
84                      const std::string&,
85                      uint32_t,
86                      const std::string&,
87                      const std::string&,
88                      AuthorizationDelegate*,
89                      std::string*));
90  MOCK_METHOD10(CreateRSAKeyPair,
91                TPM_RC(AsymmetricKeyUsage,
92                       int,
93                       uint32_t,
94                       const std::string&,
95                       const std::string&,
96                       bool,
97                       int,
98                       AuthorizationDelegate*,
99                       std::string*,
100                       std::string*));
101  MOCK_METHOD3(LoadKey,
102               TPM_RC(const std::string&, AuthorizationDelegate*, TPM_HANDLE*));
103  MOCK_METHOD2(GetKeyName, TPM_RC(TPM_HANDLE, std::string*));
104  MOCK_METHOD2(GetKeyPublicArea, TPM_RC(TPM_HANDLE, TPMT_PUBLIC*));
105  MOCK_METHOD4(SealData,
106               TPM_RC(const std::string&,
107                      const std::string&,
108                      AuthorizationDelegate*,
109                      std::string*));
110  MOCK_METHOD3(UnsealData,
111               TPM_RC(const std::string&,
112                      AuthorizationDelegate*,
113                      std::string*));
114  MOCK_METHOD1(StartSession, TPM_RC(HmacSession*));
115  MOCK_METHOD3(GetPolicyDigestForPcrValue,
116               TPM_RC(int, const std::string&, std::string*));
117  MOCK_METHOD6(DefineNVSpace,
118               TPM_RC(uint32_t,
119                      size_t,
120                      TPMA_NV,
121                      const std::string&,
122                      const std::string&,
123                      AuthorizationDelegate*));
124  MOCK_METHOD2(DestroyNVSpace, TPM_RC(uint32_t, AuthorizationDelegate*));
125  MOCK_METHOD5(LockNVSpace,
126               TPM_RC(uint32_t, bool, bool, bool, AuthorizationDelegate*));
127  MOCK_METHOD6(WriteNVSpace,
128               TPM_RC(uint32_t,
129                      uint32_t,
130                      const std::string&,
131                      bool,
132                      bool,
133                      AuthorizationDelegate*));
134  MOCK_METHOD6(ReadNVSpace,
135               TPM_RC(uint32_t,
136                      uint32_t,
137                      size_t,
138                      bool,
139                      std::string*,
140                      AuthorizationDelegate*));
141  MOCK_METHOD2(GetNVSpaceName, TPM_RC(uint32_t, std::string*));
142  MOCK_METHOD2(GetNVSpacePublicArea, TPM_RC(uint32_t, TPMS_NV_PUBLIC*));
143  MOCK_METHOD1(ListNVSpaces, TPM_RC(std::vector<uint32_t>*));
144  MOCK_METHOD4(SetDictionaryAttackParameters,
145               TPM_RC(uint32_t, uint32_t, uint32_t, AuthorizationDelegate*));
146  MOCK_METHOD1(ResetDictionaryAttackLock, TPM_RC(AuthorizationDelegate*));
147};
148
149}  // namespace trunks
150
151#endif  // TRUNKS_MOCK_TPM_UTILITY_H_
152