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 #include "user_access_ctrl_callback_stub.h"
17
18 #include "iam_logger.h"
19 #include "user_access_ctrl_callback_interface.h"
20
21 #define LOG_TAG "USER_ACCESS_CTRL_SDK"
22
23 namespace OHOS {
24 namespace UserIam {
25 namespace UserAuth {
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)26 int32_t VerifyTokenCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
27 MessageOption &option)
28 {
29 IAM_LOGI("code = %{public}u, flags = %{public}d", code, option.GetFlags());
30 if (VerifyTokenCallbackStub::GetDescriptor() != data.ReadInterfaceToken()) {
31 IAM_LOGE("descriptor is not matched");
32 return GENERAL_ERROR;
33 }
34
35 if (code == UserAccessCtrlCallbackInterfaceCode::ON_VERIFY_TOKEN_RESULT) {
36 return OnVerifyTokenResultStub(data, reply);
37 }
38 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
39 }
40
OnVerifyTokenResultStub(MessageParcel & data,MessageParcel & reply)41 int32_t VerifyTokenCallbackStub::OnVerifyTokenResultStub(MessageParcel &data, MessageParcel &reply)
42 {
43 IAM_LOGI("start");
44 int32_t result;
45 std::vector<uint8_t> buffer;
46
47 if (!data.ReadInt32(result)) {
48 IAM_LOGE("failed to read result");
49 return READ_PARCEL_ERROR;
50 }
51 if (!data.ReadUInt8Vector(&buffer)) {
52 IAM_LOGE("failed to read buffer");
53 return READ_PARCEL_ERROR;
54 }
55
56 Attributes attr(buffer);
57 OnVerifyTokenResult(result, attr);
58 return SUCCESS;
59 }
60 } // namespace UserAuth
61 } // namespace UserIam
62 } // namespace OHOS