1/* 2 * Copyright (c) 2024-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 SIGNATRUETOOLS_ZIP_ENTRY_DATA_H 17#define SIGNATRUETOOLS_ZIP_ENTRY_DATA_H 18 19#include <string> 20 21#include "data_descriptor.h" 22#include "zip_entry_header.h" 23 24namespace OHOS { 25namespace SignatureTools { 26 27class ZipEntryData { 28public: 29 /* data descriptor has or not mask */ 30 static constexpr short HAS_DATA_DESCRIPTOR_MASK = 0x08; 31 32 /* data descriptor has or not flag mask */ 33 static constexpr short NOT_HAS_DATA_DESCRIPTOR_FLAG = 0; 34 35 ZipEntryData() 36 { 37 m_zipEntryHeader = nullptr; 38 m_dataDescriptor = nullptr; 39 } 40 41 ~ZipEntryData() 42 { 43 delete m_zipEntryHeader; 44 delete m_dataDescriptor; 45 } 46 47 ZipEntryHeader* GetZipEntryHeader(); 48 49 /** 50 * init zip entry by file 51 * 52 * @param file zip file 53 * @param entryOffset entry start offset 54 * @param fileSize compress file size 55 * @return zip entry 56 * @throws IOException read zip exception 57 */ 58 static ZipEntryData* GetZipEntry(std::ifstream& input, uint32_t entryOffset, uint32_t fileSize); 59 60 void SetZipEntryHeader(ZipEntryHeader* zipEntryHeader); 61 62 DataDescriptor* GetDataDescriptor(); 63 64 void SetDataDescriptor(DataDescriptor* dataDescriptor); 65 66 uint32_t GetFileOffset(); 67 68 void SetFileOffset(uint32_t fileOffset); 69 70 uint32_t GetFileSize(); 71 72 void SetFileSize(uint32_t fileSize); 73 74 uint32_t GetLength(); 75 76 void SetLength(uint32_t length); 77 78private: 79 static bool ReadEntryFileNameAndExtraByOffset(std::ifstream& input, ZipEntryHeader* entryHeader, 80 uint32_t& offset); 81 82 ZipEntryHeader* m_zipEntryHeader; 83 84 uint32_t m_fileOffset = 0; 85 86 uint32_t m_fileSize = 0; 87 88 DataDescriptor* m_dataDescriptor; 89 90 uint32_t m_length = 0; 91}; 92} // namespace SignatureTools 93} // namespace OHOS 94#endif // SIGNATRUETOOLS_ZIP_ENTRY_DATA_H