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 "cert_parcel.h"
17 #include "dlp_permission_log.h"
18
19 namespace OHOS {
20 namespace Security {
21 namespace DlpPermission {
22 namespace {
23 static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, SECURITY_DOMAIN_DLP_PERMISSION, "CertParcel" };
24 }
25
CertParcel()26 CertParcel::CertParcel()
27 {
28 isNeedAdapter = false;
29 contactAccount = "";
30 needCheckCustomProperty = false;
31 }
32
Marshalling(Parcel & data) const33 bool CertParcel::Marshalling(Parcel& data) const
34 {
35 if (!data.WriteBool(this->isNeedAdapter)) {
36 DLP_LOG_ERROR(LABEL, "Write bool isNeedAdapter fail");
37 return false;
38 }
39 if (!data.WriteString(this->contactAccount)) {
40 DLP_LOG_ERROR(LABEL, "Write string contactAccount fail");
41 return false;
42 }
43 if (!data.WriteUInt8Vector(this->cert)) {
44 DLP_LOG_ERROR(LABEL, "Write uint8 vector fail");
45 return false;
46 }
47 if (!data.WriteUInt8Vector(this->offlineCert)) {
48 DLP_LOG_ERROR(LABEL, "Write uint8 offlineCert vector fail");
49 return false;
50 }
51 if (!data.WriteBool(this->needCheckCustomProperty)) {
52 DLP_LOG_ERROR(LABEL, "Write bool needCheckCustomProperty fail");
53 return false;
54 }
55 return true;
56 }
57
FreeCertParcel(CertParcel * parcel)58 static CertParcel* FreeCertParcel(CertParcel* parcel)
59 {
60 delete parcel;
61 return nullptr;
62 }
63
Unmarshalling(Parcel & data)64 CertParcel* CertParcel::Unmarshalling(Parcel& data)
65 {
66 auto* parcel = new (std::nothrow) CertParcel();
67 if (parcel == nullptr) {
68 DLP_LOG_ERROR(LABEL, "Alloc buff for parcel fail");
69 return nullptr;
70 }
71 if (!data.ReadBool(parcel->isNeedAdapter)) {
72 DLP_LOG_ERROR(LABEL, "Read isNeedAdapter fail");
73 return FreeCertParcel(parcel);
74 }
75 if (!data.ReadString(parcel->contactAccount)) {
76 DLP_LOG_ERROR(LABEL, "Read contactAccount fail");
77 return FreeCertParcel(parcel);
78 }
79 if (!data.ReadUInt8Vector(&parcel->cert)) {
80 DLP_LOG_ERROR(LABEL, "Read cert fail");
81 return FreeCertParcel(parcel);
82 }
83 if (!data.ReadUInt8Vector(&parcel->offlineCert)) {
84 DLP_LOG_ERROR(LABEL, "Read offlineCert fail");
85 return FreeCertParcel(parcel);
86 }
87 if (!data.ReadBool(parcel->needCheckCustomProperty)) {
88 DLP_LOG_ERROR(LABEL, "Read needCheckCustomProperty fail");
89 return FreeCertParcel(parcel);
90 }
91 return parcel;
92 }
93 } // namespace DlpPermission
94 } // namespace Security
95 } // namespace OHOS
96