1 /* 2 * Copyright (C) 2024 Huawei Device Co., Ltd. 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 STORAGE_DAEMON_FBEX_MOCK_H 16 #define STORAGE_DAEMON_FBEX_MOCK_H 17 18 #include <gmock/gmock.h> 19 #include <memory> 20 21 #include "fbex.h" 22 23 namespace OHOS { 24 namespace StorageDaemon { 25 class IFbexMoc { 26 public: 27 virtual ~IFbexMoc() = default; 28 public: 29 virtual bool IsFBEXSupported() = 0; 30 virtual int InstallKeyToKernel(uint32_t userId, uint32_t type, uint8_t *iv, uint32_t size, uint8_t flag) = 0; 31 virtual int UninstallOrLockUserKeyToKernel(uint32_t, uint32_t, uint8_t *, uint32_t, bool) = 0; 32 virtual int InstallDoubleDeKeyToKernel(UserIdToFbeStr &userIdToFbe, uint8_t *iv, uint32_t size, uint8_t flag) = 0; 33 virtual int LockScreenToKernel(uint32_t userId) = 0; 34 virtual int UnlockScreenToKernel(uint32_t userId, uint32_t type, uint8_t *iv, uint32_t size) = 0; 35 virtual int ReadESecretToKernel(UserIdToFbeStr &, uint32_t, std::unique_ptr<uint8_t[]> &, uint32_t, bool &) = 0; 36 virtual int WriteESecretToKernel(UserIdToFbeStr &, uint32_t, uint8_t *, uint32_t length) = 0; 37 virtual bool IsMspReady() = 0; 38 virtual int GetStatus() = 0; 39 virtual int InstallEL5KeyToKernel(uint32_t, uint32_t, uint8_t, bool &, bool &) = 0; 40 virtual int DeleteClassEPinCode(uint32_t userIdSingle, uint32_t userIdDouble) = 0; 41 virtual int ChangePinCodeClassE(uint32_t userIdSingle, uint32_t userIdDouble, bool &isFbeSupport) = 0; 42 virtual int GenerateAppkey(UserIdToFbeStr &, uint32_t, std::unique_ptr<uint8_t[]> &, uint32_t) = 0; 43 virtual int LockUece(uint32_t userIdSingle, uint32_t userIdDouble, bool &isFbeSupport) = 0; 44 public: 45 static inline std::shared_ptr<IFbexMoc> fbexMoc = nullptr; 46 }; 47 48 class FbexMoc : public IFbexMoc { 49 public: 50 MOCK_METHOD0(IsFBEXSupported, bool()); 51 MOCK_METHOD5(InstallKeyToKernel, int(uint32_t userId, uint32_t type, uint8_t *iv, uint32_t size, uint8_t flag)); 52 MOCK_METHOD5(UninstallOrLockUserKeyToKernel, int(uint32_t, uint32_t, uint8_t *, uint32_t, bool)); 53 MOCK_METHOD4(InstallDoubleDeKeyToKernel, int(UserIdToFbeStr &, uint8_t *iv, uint32_t size, uint8_t flag)); 54 MOCK_METHOD1(LockScreenToKernel, int(uint32_t userId)); 55 MOCK_METHOD4(UnlockScreenToKernel, int(uint32_t userId, uint32_t type, uint8_t *iv, uint32_t size)); 56 MOCK_METHOD5(ReadESecretToKernel, int(UserIdToFbeStr &, uint32_t, std::unique_ptr<uint8_t[]> &, uint32_t, bool &)); 57 MOCK_METHOD4(WriteESecretToKernel, int(UserIdToFbeStr &, uint32_t, uint8_t *, uint32_t length)); 58 MOCK_METHOD0(IsMspReady, bool()); 59 MOCK_METHOD0(GetStatus, int()); 60 MOCK_METHOD5(InstallEL5KeyToKernel, int(uint32_t, uint32_t, uint8_t, bool &, bool &)); 61 MOCK_METHOD2(DeleteClassEPinCode, int(uint32_t userIdSingle, uint32_t userIdDouble)); 62 MOCK_METHOD3(ChangePinCodeClassE, int(uint32_t userIdSingle, uint32_t userIdDouble, bool &isFbeSupport)); 63 MOCK_METHOD4(GenerateAppkey, int(UserIdToFbeStr &, uint32_t, std::unique_ptr<uint8_t[]> &, uint32_t)); 64 MOCK_METHOD3(LockUece, int(uint32_t userIdSingle, uint32_t userIdDouble, bool &isFbeSupport)); 65 }; 66 } 67 } 68 #endif