1 /*
2 * Copyright (c) 2021 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 #include "pin_auth_ui.h"
17
18 #include "dm_ability_manager.h"
19 #include "dm_constants.h"
20 #include "dm_log.h"
21 #include "nlohmann/json.hpp"
22 #include "parameter.h"
23 #include "device_manager_service_listener.h"
24
25 #include "pinauthui_fuzzer.h"
26
27 namespace OHOS {
28 namespace DistributedHardware {
PinAuthUiFuzzTest(const uint8_t * data,size_t size)29 void PinAuthUiFuzzTest(const uint8_t* data, size_t size)
30 {
31 if ((data == nullptr) || (size < sizeof(int32_t))) {
32 return;
33 }
34
35 int32_t pageId = *(reinterpret_cast<const int32_t*>(data));
36
37 std::shared_ptr<SoftbusConnector> softbusConnector = std::make_shared<SoftbusConnector>();
38 std::shared_ptr<DeviceManagerServiceListener> listener = std::make_shared<DeviceManagerServiceListener>();
39 std::shared_ptr<HiChainConnector> hiChainConnector = std::make_shared<HiChainConnector>();
40 std::shared_ptr<DmAuthManager> authManager =
41 std::make_shared<DmAuthManager>(softbusConnector, listener, hiChainConnector);
42
43 std::shared_ptr<PinAuthUi> pinauthui = std::make_shared<PinAuthUi>();
44 pinauthui->ShowPinDialog(pageId, authManager);
45 pinauthui->InputPinDialog(authManager);
46 }
47 }
48 }
49
50 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)51 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
52 {
53 /* Run your code on data */
54 OHOS::DistributedHardware::PinAuthUiFuzzTest(data, size);
55
56 return 0;
57 }
58