1 /*
2 * Copyright (c) 2021-2022 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 "hap_token_info_parcel.h"
17 #include "parcel_utils.h"
18
19 namespace OHOS {
20 namespace Security {
21 namespace AccessToken {
Marshalling(Parcel & out) const22 bool HapTokenInfoParcel::Marshalling(Parcel& out) const
23 {
24 RETURN_IF_FALSE(out.WriteInt32(this->hapTokenInfoParams.apl));
25 RETURN_IF_FALSE(out.WriteUint8(this->hapTokenInfoParams.ver));
26 RETURN_IF_FALSE(out.WriteInt32(this->hapTokenInfoParams.userID));
27 RETURN_IF_FALSE(out.WriteString(this->hapTokenInfoParams.bundleName));
28 RETURN_IF_FALSE(out.WriteInt32(this->hapTokenInfoParams.apiVersion));
29 RETURN_IF_FALSE(out.WriteInt32(this->hapTokenInfoParams.instIndex));
30 RETURN_IF_FALSE(out.WriteInt32(this->hapTokenInfoParams.dlpType));
31 RETURN_IF_FALSE(out.WriteString(this->hapTokenInfoParams.appID));
32 RETURN_IF_FALSE(out.WriteString(this->hapTokenInfoParams.deviceID));
33 RETURN_IF_FALSE(out.WriteUint32(this->hapTokenInfoParams.tokenID));
34 RETURN_IF_FALSE(out.WriteUint32(this->hapTokenInfoParams.tokenAttr));
35 return true;
36 }
37
Unmarshalling(Parcel & in)38 HapTokenInfoParcel* HapTokenInfoParcel::Unmarshalling(Parcel& in)
39 {
40 auto* hapTokenInfoParcel = new (std::nothrow) HapTokenInfoParcel();
41 if (hapTokenInfoParcel == nullptr) {
42 return nullptr;
43 }
44
45 int apl;
46 uint8_t ver;
47 RELEASE_IF_FALSE(in.ReadInt32(apl), hapTokenInfoParcel);
48 hapTokenInfoParcel->hapTokenInfoParams.apl = ATokenAplEnum(apl);
49 RELEASE_IF_FALSE(in.ReadUint8(ver), hapTokenInfoParcel);
50 hapTokenInfoParcel->hapTokenInfoParams.ver = ver;
51 RELEASE_IF_FALSE(in.ReadInt32(hapTokenInfoParcel->hapTokenInfoParams.userID), hapTokenInfoParcel);
52 hapTokenInfoParcel->hapTokenInfoParams.bundleName = in.ReadString();
53 RELEASE_IF_FALSE(in.ReadInt32(hapTokenInfoParcel->hapTokenInfoParams.apiVersion), hapTokenInfoParcel);
54 RELEASE_IF_FALSE(in.ReadInt32(hapTokenInfoParcel->hapTokenInfoParams.instIndex), hapTokenInfoParcel);
55 RELEASE_IF_FALSE(in.ReadInt32(hapTokenInfoParcel->hapTokenInfoParams.dlpType), hapTokenInfoParcel);
56 hapTokenInfoParcel->hapTokenInfoParams.appID = in.ReadString();
57 hapTokenInfoParcel->hapTokenInfoParams.deviceID = in.ReadString();
58 RELEASE_IF_FALSE(in.ReadUint32(hapTokenInfoParcel->hapTokenInfoParams.tokenID), hapTokenInfoParcel);
59 RELEASE_IF_FALSE(in.ReadUint32(hapTokenInfoParcel->hapTokenInfoParams.tokenAttr), hapTokenInfoParcel);
60 return hapTokenInfoParcel;
61 }
62 } // namespace AccessToken
63 } // namespace Security
64 } // namespace OHOS
65