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 "inputer_get_data_stub.h"
17
18 #include "iam_logger.h"
19 #include "iam_common_defines.h"
20
21 #define LOG_TAG "PIN_AUTH_SDK"
22
23 namespace OHOS {
24 namespace UserIam {
25 namespace PinAuth {
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)26 int32_t InputerGetDataStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
27 MessageOption &option)
28 {
29 IAM_LOGI("cmd = %{public}u, flags = %{public}d", code, option.GetFlags());
30 if (InputerGetDataStub::GetDescriptor() != data.ReadInterfaceToken()) {
31 IAM_LOGE("descriptor is not matched");
32 return UserAuth::GENERAL_ERROR;
33 }
34 switch (code) {
35 case InputerGetDataInterfaceCode::ON_GET_DATA:
36 OnGetDataStub(data, reply);
37 return UserAuth::SUCCESS;
38 default:
39 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
40 }
41 }
42
ReadInputerGetDataParam(MessageParcel & data,InputerGetDataParam & getDataParam)43 bool InputerGetDataStub::ReadInputerGetDataParam(MessageParcel &data, InputerGetDataParam &getDataParam)
44 {
45 int32_t mode;
46 if (!data.ReadInt32(mode)) {
47 IAM_LOGE("failed to read mode");
48 return false;
49 }
50 getDataParam.mode = static_cast<GetDataMode>(mode);
51 if (!data.ReadInt32(getDataParam.authSubType)) {
52 IAM_LOGE("failed to read authSubType");
53 return false;
54 }
55 if (!data.ReadUint32(getDataParam.algoVersion)) {
56 IAM_LOGE("failed to read algoVersion");
57 return false;
58 }
59 if (!data.ReadUInt8Vector(&(getDataParam.algoParameter))) {
60 IAM_LOGE("failed to read algoParameter");
61 return false;
62 }
63 if (!data.ReadUInt8Vector(&(getDataParam.challenge))) {
64 IAM_LOGE("failed to read challenge");
65 return false;
66 }
67 if (!data.ReadInt32(getDataParam.userId)) {
68 IAM_LOGE("failed to read userId");
69 return false;
70 }
71 if (!data.ReadString(getDataParam.complexityReg)) {
72 IAM_LOGE("failed to read complexityReg");
73 return false;
74 }
75 if (!data.ReadInt32(getDataParam.authIntent)) {
76 IAM_LOGE("failed to read authIntent");
77 return false;
78 }
79 sptr<IRemoteObject> obj = data.ReadRemoteObject();
80 if (obj == nullptr) {
81 IAM_LOGE("failed to read remote object");
82 return false;
83 }
84 getDataParam.inputerSetData = iface_cast<InputerSetData>(obj);
85 if (getDataParam.inputerSetData == nullptr) {
86 IAM_LOGE("inputerSetData is nullptr");
87 return false;
88 }
89 return true;
90 }
91
OnGetDataStub(MessageParcel & data,MessageParcel & reply)92 void InputerGetDataStub::OnGetDataStub(MessageParcel &data, MessageParcel &reply)
93 {
94 InputerGetDataParam getDataParam;
95 if (!ReadInputerGetDataParam(data, getDataParam)) {
96 IAM_LOGE("ReadInputerGetDataParam failed");
97 return;
98 }
99 OnGetData(getDataParam);
100 }
101 } // namespace PinAuth
102 } // namespace UserIam
103 } // namespace OHOS
104