1 /*
2 * Copyright (c) 2023 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 "auth_user_info_parcel.h"
17 #include "dlp_permission_log.h"
18 #include "securec.h"
19
20 namespace OHOS {
21 namespace Security {
22 namespace DlpPermission {
23 namespace {
24 static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_DLP_PERMISSION, "DlpPermissionParcel"};
25 }
Marshalling(Parcel & out) const26 bool AuthUserInfoParcel::Marshalling(Parcel& out) const
27 {
28 if (!(out.WriteString(this->authUserInfo_.authAccount))) {
29 DLP_LOG_ERROR(LABEL, "Write auth user account fail");
30 return false;
31 }
32 if (!(out.WriteUint8(this->authUserInfo_.authPerm))) {
33 DLP_LOG_ERROR(LABEL, "Write auth user perm fail");
34 return false;
35 }
36 if (!(out.WriteUint64(this->authUserInfo_.permExpiryTime))) {
37 DLP_LOG_ERROR(LABEL, "Write auth user expiry time fail");
38 return false;
39 }
40 if (!(out.WriteUint8(this->authUserInfo_.authAccountType))) {
41 DLP_LOG_ERROR(LABEL, "Write auth user account type fail");
42 return false;
43 }
44 return true;
45 }
46
Unmarshalling(Parcel & in)47 AuthUserInfoParcel* AuthUserInfoParcel::Unmarshalling(Parcel& in)
48 {
49 auto authUserInfoParcel = new (std::nothrow) AuthUserInfoParcel();
50 if (authUserInfoParcel == nullptr) {
51 DLP_LOG_ERROR(LABEL, "Alloc buff for auth user info parcel fail");
52 return nullptr;
53 }
54
55 if (!(in.ReadString(authUserInfoParcel->authUserInfo_.authAccount))) {
56 DLP_LOG_ERROR(LABEL, "Read auth user account fail");
57 delete authUserInfoParcel;
58 authUserInfoParcel = nullptr;
59 return nullptr;
60 }
61 uint8_t res;
62 if (!(in.ReadUint8(res))) {
63 DLP_LOG_ERROR(LABEL, "Read auth user perm fail");
64 delete authUserInfoParcel;
65 authUserInfoParcel = nullptr;
66 return nullptr;
67 }
68 authUserInfoParcel->authUserInfo_.authPerm = static_cast<DLPFileAccess>(res);
69 if (!(in.ReadUint64(authUserInfoParcel->authUserInfo_.permExpiryTime))) {
70 DLP_LOG_ERROR(LABEL, "Read auth user expiry time fail");
71 delete authUserInfoParcel;
72 authUserInfoParcel = nullptr;
73 return nullptr;
74 }
75
76 if (!(in.ReadUint8(res))) {
77 DLP_LOG_ERROR(LABEL, "Read auth user account type fail");
78 delete authUserInfoParcel;
79 authUserInfoParcel = nullptr;
80 return nullptr;
81 }
82 authUserInfoParcel->authUserInfo_.authAccountType = static_cast<DlpAccountType>(res);
83
84 return authUserInfoParcel;
85 }
86 } // namespace DlpPermission
87 } // namespace Security
88 } // namespace OHOS
89