• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 }
31 
Marshalling(Parcel & data) const32 bool CertParcel::Marshalling(Parcel& data) const
33 {
34     if (!data.WriteBool(this->isNeedAdapter)) {
35         DLP_LOG_ERROR(LABEL, "Write bool isNeedAdapter fail");
36         return false;
37     }
38     if (!data.WriteString(this->contactAccount)) {
39         DLP_LOG_ERROR(LABEL, "Write string contactAccount fail");
40         return false;
41     }
42     if (!data.WriteUInt8Vector(this->cert)) {
43         DLP_LOG_ERROR(LABEL, "Write uint8 vector fail");
44         return false;
45     }
46     if (!data.WriteUInt8Vector(this->offlineCert)) {
47         DLP_LOG_ERROR(LABEL, "Write uint8 offlineCert vector fail");
48         return false;
49     }
50     return true;
51 }
52 
FreeCertParcel(CertParcel * parcel)53 static CertParcel* FreeCertParcel(CertParcel* parcel)
54 {
55     delete parcel;
56     parcel = nullptr;
57     return nullptr;
58 }
59 
Unmarshalling(Parcel & data)60 CertParcel* CertParcel::Unmarshalling(Parcel& data)
61 {
62     auto* parcel = new (std::nothrow) CertParcel();
63     if (parcel == nullptr) {
64         DLP_LOG_ERROR(LABEL, "Alloc buff for parcel fail");
65         return nullptr;
66     }
67     if (!data.ReadBool(parcel->isNeedAdapter)) {
68         DLP_LOG_ERROR(LABEL, "Read isNeedAdapter fail");
69         return FreeCertParcel(parcel);
70     }
71     if (!data.ReadString(parcel->contactAccount)) {
72         DLP_LOG_ERROR(LABEL, "Read contactAccount fail");
73         return FreeCertParcel(parcel);
74     }
75     if (!data.ReadUInt8Vector(&parcel->cert)) {
76         DLP_LOG_ERROR(LABEL, "Read cert fail");
77         return FreeCertParcel(parcel);
78     }
79     if (!data.ReadUInt8Vector(&parcel->offlineCert)) {
80         DLP_LOG_ERROR(LABEL, "Read cert fail");
81         return FreeCertParcel(parcel);
82     }
83     return parcel;
84 }
85 } // namespace DlpPermission
86 } // namespace Security
87 } // namespace OHOS
88