1 // 2 // Copyright (C) 2015 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 TPM_MANAGER_SERVER_MOCK_TPM_NVRAM_H_ 18 #define TPM_MANAGER_SERVER_MOCK_TPM_NVRAM_H_ 19 20 #include "tpm_manager/server/tpm_nvram.h" 21 22 #include <map> 23 #include <string> 24 25 #include <gmock/gmock.h> 26 27 namespace tpm_manager { 28 29 struct NvSpace { 30 std::string data; 31 bool read_locked; 32 bool write_locked; 33 std::vector<NvramSpaceAttribute> attributes; 34 std::string authorization_value; 35 NvramSpacePolicy policy; 36 }; 37 38 class MockTpmNvram : public TpmNvram { 39 public: 40 MockTpmNvram(); 41 ~MockTpmNvram() override; 42 43 MOCK_METHOD5(DefineSpace, 44 NvramResult(uint32_t, 45 size_t, 46 const std::vector<NvramSpaceAttribute>&, 47 const std::string&, 48 NvramSpacePolicy)); 49 MOCK_METHOD1(DestroySpace, NvramResult(uint32_t)); 50 MOCK_METHOD3(WriteSpace, 51 NvramResult(uint32_t, const std::string&, const std::string&)); 52 MOCK_METHOD3(ReadSpace, 53 NvramResult(uint32_t, std::string*, const std::string&)); 54 MOCK_METHOD4(LockSpace, 55 NvramResult(uint32_t, bool, bool, const std::string&)); 56 MOCK_METHOD1(ListSpaces, NvramResult(std::vector<uint32_t>*)); 57 MOCK_METHOD6(GetSpaceInfo, 58 NvramResult(uint32_t, 59 size_t*, 60 bool*, 61 bool*, 62 std::vector<NvramSpaceAttribute>*, 63 NvramSpacePolicy*)); 64 65 private: 66 NvramResult FakeDefineSpace( 67 uint32_t index, 68 size_t size, 69 const std::vector<NvramSpaceAttribute>& attributes, 70 const std::string& authorization_value, 71 NvramSpacePolicy policy); 72 NvramResult FakeDestroySpace(uint32_t index); 73 NvramResult FakeWriteSpace(uint32_t index, 74 const std::string& data, 75 const std::string& authorization_value); 76 NvramResult FakeReadSpace(uint32_t index, 77 std::string* data, 78 const std::string& authorization_value); 79 NvramResult FakeLockSpace(uint32_t index, 80 bool lock_read, 81 bool lock_write, 82 const std::string& authorization_value); 83 NvramResult FakeListSpaces(std::vector<uint32_t>* index_list); 84 NvramResult FakeGetSpaceInfo(uint32_t index, 85 size_t* size, 86 bool* is_read_locked, 87 bool* is_write_locked, 88 std::vector<NvramSpaceAttribute>* attributes, 89 NvramSpacePolicy* policy); 90 91 std::map<uint32_t, NvSpace> nvram_map_; 92 }; 93 94 } // namespace tpm_manager 95 96 #endif // TPM_MANAGER_SERVER_MOCK_TPM_NVRAM_H_ 97