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 26 namespace trunks { 27 28 class 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, TPM_RC(const std::string&, 39 const std::string&, 40 const std::string&)); 41 MOCK_METHOD2(StirRandom, TPM_RC(const std::string&, AuthorizationDelegate*)); 42 MOCK_METHOD3(GenerateRandom, TPM_RC(size_t, 43 AuthorizationDelegate*, 44 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, TPM_RC(TPM_HANDLE, 49 TPM_ALG_ID, 50 TPM_ALG_ID, 51 const std::string&, 52 AuthorizationDelegate*, 53 std::string*)); 54 MOCK_METHOD6(AsymmetricDecrypt, TPM_RC(TPM_HANDLE, 55 TPM_ALG_ID, 56 TPM_ALG_ID, 57 const std::string&, 58 AuthorizationDelegate*, 59 std::string*)); 60 MOCK_METHOD6(Sign, TPM_RC(TPM_HANDLE, 61 TPM_ALG_ID, 62 TPM_ALG_ID, 63 const std::string&, 64 AuthorizationDelegate*, 65 std::string*)); 66 MOCK_METHOD6(Verify, TPM_RC(TPM_HANDLE, 67 TPM_ALG_ID, 68 TPM_ALG_ID, 69 const std::string&, 70 const std::string&, 71 AuthorizationDelegate*)); 72 MOCK_METHOD2(CertifyCreation, TPM_RC(TPM_HANDLE, 73 const std::string&)); 74 MOCK_METHOD4(ChangeKeyAuthorizationData, TPM_RC(TPM_HANDLE, 75 const std::string&, 76 AuthorizationDelegate*, 77 std::string*)); 78 MOCK_METHOD7(ImportRSAKey, TPM_RC(AsymmetricKeyUsage, 79 const std::string&, 80 uint32_t, 81 const std::string&, 82 const std::string&, 83 AuthorizationDelegate*, 84 std::string*)); 85 MOCK_METHOD10(CreateRSAKeyPair, TPM_RC(AsymmetricKeyUsage, 86 int, 87 uint32_t, 88 const std::string&, 89 const std::string&, 90 bool, 91 int, 92 AuthorizationDelegate*, 93 std::string*, 94 std::string*)); 95 MOCK_METHOD3(LoadKey, TPM_RC(const std::string&, 96 AuthorizationDelegate*, 97 TPM_HANDLE*)); 98 MOCK_METHOD2(GetKeyName, TPM_RC(TPM_HANDLE, std::string*)); 99 MOCK_METHOD2(GetKeyPublicArea, TPM_RC(TPM_HANDLE, TPMT_PUBLIC*)); 100 MOCK_METHOD4(SealData, TPM_RC(const std::string&, 101 const std::string&, 102 AuthorizationDelegate*, 103 std::string*)); 104 MOCK_METHOD3(UnsealData, TPM_RC(const std::string&, 105 AuthorizationDelegate*, 106 std::string*)); 107 MOCK_METHOD1(StartSession, TPM_RC(HmacSession*)); 108 MOCK_METHOD3(GetPolicyDigestForPcrValue, TPM_RC(int, 109 const std::string&, 110 std::string*)); 111 MOCK_METHOD3(DefineNVSpace, TPM_RC(uint32_t, 112 size_t, 113 AuthorizationDelegate*)); 114 MOCK_METHOD2(DestroyNVSpace, TPM_RC(uint32_t, 115 AuthorizationDelegate*)); 116 MOCK_METHOD2(LockNVSpace, TPM_RC(uint32_t, 117 AuthorizationDelegate*)); 118 MOCK_METHOD4(WriteNVSpace, TPM_RC(uint32_t, 119 uint32_t, 120 const std::string&, 121 AuthorizationDelegate*)); 122 MOCK_METHOD5(ReadNVSpace, TPM_RC(uint32_t, 123 uint32_t, 124 size_t, 125 std::string*, 126 AuthorizationDelegate*)); 127 MOCK_METHOD2(GetNVSpaceName, TPM_RC(uint32_t, std::string*)); 128 MOCK_METHOD2(GetNVSpacePublicArea, TPM_RC(uint32_t, TPMS_NV_PUBLIC*)); 129 }; 130 131 } // namespace trunks 132 133 #endif // TRUNKS_MOCK_TPM_UTILITY_H_ 134