1 /* 2 * Copyright (c) 2024 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 #ifndef SECURITY_CONFIG_UPDATE_H 17 #define SECURITY_CONFIG_UPDATE_H 18 19 #include <string> 20 21 #include "parcel.h" 22 23 namespace OHOS::Security::SecurityGuard { 24 class SecurityConfigUpdateInfo : public Parcelable { 25 public: 26 SecurityConfigUpdateInfo() = default; fd_(fd)27 SecurityConfigUpdateInfo(int32_t fd, const std::string &name = "") : fd_(fd), fileName_(name) {}; 28 ~SecurityConfigUpdateInfo() override = default; Marshalling(Parcel & parcel)29 bool Marshalling(Parcel& parcel) const override 30 { 31 if (!parcel.WriteInt32(fd_)) { 32 return false; 33 } 34 if (!parcel.WriteString(fileName_)) { 35 return false; 36 } 37 return true; 38 } ReadFromParcel(Parcel & parcel)39 bool ReadFromParcel(Parcel &parcel) 40 { 41 if (!parcel.ReadInt32(fd_)) { 42 return false; 43 } 44 if (!parcel.ReadString(fileName_)) { 45 return false; 46 } 47 return true; 48 } Unmarshalling(Parcel & parcel)49 static SecurityConfigUpdateInfo* Unmarshalling(Parcel& parcel) 50 { 51 SecurityConfigUpdateInfo *info = new (std::nothrow) SecurityConfigUpdateInfo(); 52 if (info != nullptr && !info->ReadFromParcel(parcel)) { 53 delete info; 54 info = nullptr; 55 } 56 return info; 57 } GetFd()58 int32_t GetFd() const { return fd_; }; GetFileName()59 std::string GetFileName() const { return fileName_; }; 60 private: 61 int32_t fd_{}; 62 std::string fileName_{}; 63 }; 64 } // namespace OHOS::Security::SecurityGuard 65 66 #endif // SECURITY_CONFIG_UPDATE_H