• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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_executor_callback_hdi.h"
17 
18 #include <cinttypes>
19 #include <v1_0/iexecutor.h>
20 #include <hdf_base.h>
21 
22 #include "iam_logger.h"
23 #include "iam_common_defines.h"
24 #include "i_inputer_data_impl.h"
25 #include "inputer_get_data_proxy.h"
26 #include "v1_0/pin_auth_types.h"
27 
28 #define LOG_LABEL UserIam::Common::LABEL_PIN_AUTH_SA
29 
30 namespace OHOS {
31 namespace UserIam {
32 namespace PinAuth {
PinAuthExecutorCallbackHdi(std::shared_ptr<UserIam::UserAuth::IExecuteCallback> frameworkCallback,std::shared_ptr<PinAuthExecutorHdi> pinAuthExecutorHdi,uint32_t tokenId)33 PinAuthExecutorCallbackHdi::PinAuthExecutorCallbackHdi(std::shared_ptr<UserIam::UserAuth::IExecuteCallback>
34     frameworkCallback, std::shared_ptr<PinAuthExecutorHdi> pinAuthExecutorHdi, uint32_t tokenId)
35     : frameworkCallback_(frameworkCallback), pinAuthExecutorHdi_(pinAuthExecutorHdi), tokenId_(tokenId) {}
36 
OnResult(int32_t code,const std::vector<uint8_t> & extraInfo)37 int32_t PinAuthExecutorCallbackHdi::OnResult(int32_t code, const std::vector<uint8_t>& extraInfo)
38 {
39     IAM_LOGI("OnResult %{public}d", code);
40     UserAuth::ResultCode retCode = ConvertResultCode(code);
41     frameworkCallback_->OnResult(retCode, extraInfo);
42     return HDF_SUCCESS;
43 }
44 
OnGetData(uint64_t scheduleId,const std::vector<uint8_t> & salt,uint64_t authSubType)45 int32_t PinAuthExecutorCallbackHdi::OnGetData(uint64_t scheduleId, const std::vector<uint8_t>& salt,
46     uint64_t authSubType)
47 {
48     IAM_LOGI("Start tokenId_ is %{public}u", tokenId_);
49     sptr<InputerGetData> inputer = PinAuthManager::GetInstance().GetInputerLock(tokenId_);
50     if (inputer == nullptr) {
51         IAM_LOGE("inputer is nullptr");
52         return HDF_FAILURE;
53     }
54     sptr<IInputerDataImpl> iInputerDataImpl = new (std::nothrow) IInputerDataImpl(scheduleId, pinAuthExecutorHdi_);
55     if (iInputerDataImpl == nullptr) {
56         IAM_LOGE("iInputerDataImpl is nullptr");
57     }
58     inputer->OnGetData(authSubType, salt, iInputerDataImpl);
59     return HDF_SUCCESS;
60 }
61 
ConvertResultCode(const int32_t in)62 UserAuth::ResultCode PinAuthExecutorCallbackHdi::ConvertResultCode(const int32_t in)
63 {
64     UserAuth::ResultCode hdiIn = static_cast<UserAuth::ResultCode>(in);
65     if (hdiIn < UserAuth::ResultCode::SUCCESS || hdiIn > UserAuth::ResultCode::LOCKED) {
66         IAM_LOGE("convert hdi undefined result code %{public}d to framework result code GENERAL_ERROR", hdiIn);
67         return UserAuth::ResultCode::GENERAL_ERROR;
68     }
69 
70     IAM_LOGI("covert hdi result code %{public}d to framework result code", hdiIn);
71     return hdiIn;
72 }
73 } // PinAuth
74 } // UserIam
75 } // OHOS