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_DATA_DESCRIPTOR_H 17#define SIGNATRUETOOLS_DATA_DESCRIPTOR_H 18 19#include "byte_buffer.h" 20 21namespace OHOS { 22namespace SignatureTools { 23/** 24 * resolve zip DataDescriptor data 25 * DataDescriptor format: 26 * crc-32 4 bytes 27 * compressed size 4 bytes 28 * uncompressed size 4 bytes 29 */ 30class DataDescriptor { 31public: 32 /* DataDescriptor invariable bytes length */ 33 static constexpr int DES_LENGTH = 16; 34 35 /* 4 bytes , DataDescriptor signature */ 36 static constexpr int SIGNATURE = 0x08074b50; 37 38 /** 39 * get Data Descriptor 40 * 41 * @param bytes DataDescriptor bytes 42 * @return DataDescriptor 43 * @throws ZipException read data descriptor exception 44 */ 45 static DataDescriptor* GetDataDescriptor(const std::string& bytes); 46 47 std::string ToBytes(); 48 49 static int GetDesLength(); 50 51 static int GetSIGNATURE(); 52 53 int GetCrc32(); 54 55 void SetCrc32(int crc32); 56 57 uint32_t GetCompressedSize(); 58 59 void SetCompressedSize(uint32_t compressedSize); 60 61 uint32_t GetUnCompressedSize(); 62 63 void SetUnCompressedSize(uint32_t unCompressedSize); 64 65private: 66 /* 4 bytes */ 67 int m_crc32 = 0; 68 69 /* 4 bytes */ 70 uint32_t m_compressedSize = 0; 71 72 /* 4 bytes */ 73 uint32_t m_unCompressedSize = 0; 74}; 75} // namespace SignatureTools 76} // namespace OHOS 77#endif // SIGNATRUETOOLS_DATA_DESCRIPTOR_H