1 /*
2 * Copyright (c) 2025 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 "ipc/encryption_param.h"
17
18 #include "parcel_macro.h"
19 #include "string_ex.h"
20
21 namespace OHOS {
22 namespace AppExecFwk {
EncryptionParam(const std::string & name,const std::string & id,int32_t uidParam,int32_t userIdParam,EncryptionDirType dirType)23 EncryptionParam::EncryptionParam(const std::string &name, const std::string &id, int32_t uidParam, int32_t userIdParam,
24 EncryptionDirType dirType) : bundleName(name), groupId(id), uid(uidParam),
25 userId(userIdParam), encryptionDirType(dirType) {};
26
ReadFromParcel(Parcel & parcel)27 bool EncryptionParam::ReadFromParcel(Parcel &parcel)
28 {
29 bundleName = Str16ToStr8(parcel.ReadString16());
30 groupId = Str16ToStr8(parcel.ReadString16());
31 uid = parcel.ReadInt32();
32 userId = parcel.ReadInt32();
33 encryptionDirType = static_cast<EncryptionDirType>(parcel.ReadUint8());
34 return true;
35 }
36
Marshalling(Parcel & parcel) const37 bool EncryptionParam::Marshalling(Parcel &parcel) const
38 {
39 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(bundleName));
40 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(groupId));
41 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, uid);
42 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, userId);
43 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint8, parcel, static_cast<uint8_t>(encryptionDirType));
44 return true;
45 }
46
Unmarshalling(Parcel & parcel)47 EncryptionParam *EncryptionParam::Unmarshalling(Parcel &parcel)
48 {
49 EncryptionParam *info = new (std::nothrow) EncryptionParam();
50 if (info != nullptr && !info->ReadFromParcel(parcel)) {
51 APP_LOGE("read from parcel failed");
52 delete info;
53 info = nullptr;
54 }
55 return info;
56 }
57 } // namespace AppExecFwk
58 } // namespace OHOS
59