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 
16 #ifndef MOCK_IALL_IN_ONE_EXECUTOR_FUZZER_H
17 #define MOCK_IALL_IN_ONE_EXECUTOR_FUZZER_H
18 
19 #include "iam_common_defines.h"
20 #include "pin_auth_hdi.h"
21 
22 namespace OHOS {
23 namespace UserIam {
24 namespace PinAuth {
25 using namespace OHOS;
26 using namespace OHOS::HDI::PinAuth::V2_1;
27 class MockIAllInOneExecutorFuzzer : public IAllInOneExecutor {
28 public:
29     virtual ~MockIAllInOneExecutorFuzzer() = default;
GetExecutorInfo(ExecutorInfo & executorInfo)30     int32_t GetExecutorInfo(ExecutorInfo& executorInfo) override
31     {
32         return isTrueTest();
33     }
34 
OnRegisterFinish(const std::vector<uint64_t> & templateIdList,const std::vector<uint8_t> & frameworkPublicKey,const std::vector<uint8_t> & extraInfo)35     int32_t OnRegisterFinish(const std::vector<uint64_t>& templateIdList,
36          const std::vector<uint8_t>& frameworkPublicKey, const std::vector<uint8_t>& extraInfo) override
37     {
38         return isTrueTest();
39     }
40 
Cancel(uint64_t scheduleId)41     int32_t Cancel(uint64_t scheduleId) override
42     {
43         return isTrueTest();
44     }
45 
SendMessage(uint64_t scheduleId,int32_t srcRole,const std::vector<uint8_t> & msg)46     int32_t SendMessage(uint64_t scheduleId, int32_t srcRole, const std::vector<uint8_t>& msg) override
47     {
48         return isTrueTest();
49     }
50 
SetData(uint64_t scheduleId,uint64_t authSubType,const std::vector<uint8_t> & data,int32_t resultCode)51     int32_t SetData(uint64_t scheduleId, uint64_t authSubType, const std::vector<uint8_t>& data,
52          int32_t resultCode) override
53     {
54         return isTrueTest();
55     }
56 
Enroll(uint64_t scheduleId,const std::vector<uint8_t> & extraInfo,const sptr<IExecutorCallback> & callbackObj)57     int32_t Enroll(uint64_t scheduleId, const std::vector<uint8_t>& extraInfo,
58          const sptr<IExecutorCallback>& callbackObj) override
59     {
60         return isTrueTest();
61     }
62 
Authenticate(uint64_t scheduleId,const std::vector<uint64_t> & templateIdList,const std::vector<uint8_t> & extraInfo,const sptr<IExecutorCallback> & callbackObj)63     int32_t Authenticate(uint64_t scheduleId, const std::vector<uint64_t>& templateIdList,
64          const std::vector<uint8_t>& extraInfo, const sptr<IExecutorCallback>& callbackObj) override
65     {
66         return isTrueTest();
67     }
68 
Delete(uint64_t templateId)69     int32_t Delete(uint64_t templateId) override
70     {
71         return isTrueTest();
72     }
73 
GetProperty(const std::vector<uint64_t> & templateIdList,const std::vector<int32_t> & propertyTypes,Property & property)74     int32_t GetProperty(const std::vector<uint64_t>& templateIdList, const std::vector<int32_t>& propertyTypes,
75          Property& property) override
76     {
77         return isTrueTest();
78     }
SendCommand(int32_t commandId,const std::vector<uint8_t> & extraInfo,const sptr<IExecutorCallback> & callbackObj)79     int32_t SendCommand(int32_t commandId, const std::vector<uint8_t> &extraInfo,
80         const sptr<IExecutorCallback> &callbackObj) override
81     {
82         return isTrueTest();
83     }
84 private:
85     bool isTrue_ = false;
86     int32_t isTrueTest();
87 };
88 
isTrueTest()89 int32_t MockIAllInOneExecutorFuzzer::isTrueTest()
90 {
91     isTrue_ = !isTrue_;
92     return isTrue_ ? UserAuth::ResultCode::SUCCESS : UserAuth::ResultCode::FAIL;
93 }
94 
95 } // namespace PinAuth
96 } // namespace UserIam
97 } // namespace OHOS
98 
99 #endif // MOCK_IALL_IN_ONE_EXECUTOR_FUZZER_H