1 /*
2  * Copyright (c) 2022-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 #include "v2_1/pin_auth_interface_service.h"
17 
18 #include <hdf_base.h>
19 
20 #include "iam_logger.h"
21 #include "iam_ptr.h"
22 
23 #include "pin_auth_hdi.h"
24 #include "pin_auth.h"
25 #include "all_in_one_impl.h"
26 #include "collector_impl.h"
27 #include "verifier_impl.h"
28 
29 #undef LOG_TAG
30 #define LOG_TAG "PIN_AUTH_HDI"
31 
32 namespace OHOS {
33 namespace HDI {
34 namespace PinAuth {
PinAuthInterfaceImplGetInstance(void)35 extern "C" IPinAuthInterface *PinAuthInterfaceImplGetInstance(void)
36 {
37     auto pinAuthInterfaceService = new (std::nothrow) PinAuthInterfaceService();
38     if (pinAuthInterfaceService == nullptr) {
39         IAM_LOGE("pinAuthInterfaceService is nullptr");
40         return nullptr;
41     }
42     return pinAuthInterfaceService;
43 }
44 
GetExecutorList(std::vector<sptr<HdiIAllInOneExecutor>> & allInOneExecutors,std::vector<sptr<HdiIVerifier>> & verifiers,std::vector<sptr<HdiICollector>> & collectors)45 int32_t PinAuthInterfaceService::GetExecutorList(std::vector<sptr<HdiIAllInOneExecutor>>& allInOneExecutors,
46     std::vector<sptr<HdiIVerifier>>& verifiers, std::vector<sptr<HdiICollector>>& collectors)
47 {
48     IAM_LOGI("start");
49     static_cast<void>(verifiers);
50     static_cast<void>(collectors);
51     std::shared_ptr<OHOS::UserIam::PinAuth::PinAuth> pinHdi =
52         OHOS::UserIam::Common::MakeShared<OHOS::UserIam::PinAuth::PinAuth>();
53     if (pinHdi == nullptr) {
54         IAM_LOGE("Generate pinHdi failed");
55         return HDF_FAILURE;
56     }
57     sptr<HdiIAllInOneExecutor> allInOneImpl(new (std::nothrow) AllInOneImpl(pinHdi));
58     if (allInOneImpl == nullptr) {
59         IAM_LOGE("Generate all in one executor failed");
60         return HDF_FAILURE;
61     }
62     allInOneExecutors.push_back(allInOneImpl);
63     sptr<HdiIVerifier> verifierImpl(new (std::nothrow) VerifierImpl(pinHdi));
64     if (verifierImpl == nullptr) {
65         IAM_LOGE("Generate verifierImpl failed");
66         return HDF_FAILURE;
67     }
68     verifiers.push_back(verifierImpl);
69     sptr<HdiICollector> collectorImpl(new (std::nothrow) CollectorImpl(pinHdi));
70     if (collectorImpl == nullptr) {
71         IAM_LOGE("Generate collectorImpl failed");
72         return HDF_FAILURE;
73     }
74     collectors.push_back(collectorImpl);
75     IAM_LOGI("end");
76     return HDF_SUCCESS;
77 }
78 } // PinAuth
79 } // HDI
80 } // OHOS