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_ICOLLECTOR_EXECUTOR_FUZZER_H
17 #define MOCK_ICOLLECTOR_EXECUTOR_FUZZER_H
18
19 #include "pin_auth_hdi.h"
20
21 namespace OHOS {
22 namespace UserIam {
23 namespace PinAuth {
24 using namespace OHOS;
25 using namespace OHOS::HDI::PinAuth::V2_1;
26 class MockICollectorExecutorFuzzer : public ICollector {
27 public:
28 virtual ~MockICollectorExecutorFuzzer() = default;
GetExecutorInfo(ExecutorInfo & executorInfo)29 int32_t GetExecutorInfo(ExecutorInfo& executorInfo) override
30 {
31 return isTrueTest();
32 }
33
OnRegisterFinish(const std::vector<uint64_t> & templateIdList,const std::vector<uint8_t> & frameworkPublicKey,const std::vector<uint8_t> & extraInfo)34 int32_t OnRegisterFinish(const std::vector<uint64_t>& templateIdList,
35 const std::vector<uint8_t>& frameworkPublicKey, const std::vector<uint8_t>& extraInfo) override
36 {
37 return isTrueTest();
38 }
39
Cancel(uint64_t scheduleId)40 int32_t Cancel(uint64_t scheduleId) override
41 {
42 return isTrueTest();
43 }
44
SendMessage(uint64_t scheduleId,int32_t srcRole,const std::vector<uint8_t> & msg)45 int32_t SendMessage(uint64_t scheduleId, int32_t srcRole, const std::vector<uint8_t>& msg) override
46 {
47 return isTrueTest();
48 }
49
SetData(uint64_t scheduleId,uint64_t authSubType,const std::vector<uint8_t> & data,int32_t resultCode)50 int32_t SetData(uint64_t scheduleId, uint64_t authSubType, const std::vector<uint8_t>& data,
51 int32_t resultCode) override
52 {
53 return isTrueTest();
54 }
55
Collect(uint64_t scheduleId,const std::vector<uint8_t> & extraInfo,const sptr<IExecutorCallback> & callbackObj)56 int32_t Collect(uint64_t scheduleId, const std::vector<uint8_t>& extraInfo,
57 const sptr<IExecutorCallback>& callbackObj) override
58 {
59 return isTrueTest();
60 }
61
62 private:
63 bool isTrue_ = false;
64 int32_t isTrueTest();
65 };
66
isTrueTest()67 int32_t MockICollectorExecutorFuzzer::isTrueTest()
68 {
69 isTrue_ = !isTrue_;
70 return isTrue_ ? UserAuth::ResultCode::SUCCESS : UserAuth::ResultCode::FAIL;
71 }
72
73 } // namespace PinAuth
74 } // namespace UserIam
75 } // namespace OHOS
76
77 #endif // MOCK_ICOLLECTOR_EXECUTOR_FUZZER_H