• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 LZ4_PKG_FILE_H
17 #define LZ4_PKG_FILE_H
18 
19 #include "pkg_pkgfile.h"
20 #include "pkg_utils.h"
21 
22 namespace Hpackage {
23 class Lz4FileEntry : public PkgEntry {
24 public:
Lz4FileEntry(PkgFilePtr pkgFile,uint32_t nodeId)25     Lz4FileEntry(PkgFilePtr pkgFile, uint32_t nodeId) : PkgEntry(pkgFile, nodeId)
26     {
27         fileInfo_.compressionLevel = 0;
28         fileInfo_.blockIndependence = 0;
29         fileInfo_.blockSizeID = 0;
30         fileInfo_.contentChecksumFlag = 0;
31     }
32 
~Lz4FileEntry()33     ~Lz4FileEntry() override {}
34 
35     int32_t Init(const PkgManager::FileInfoPtr fileInfo, PkgStreamPtr inStream) override;
36 
GetFileInfo()37     const FileInfo *GetFileInfo() const override
38     {
39         return &fileInfo_.fileInfo;
40     };
41 
42     int32_t EncodeHeader(PkgStreamPtr inStream, size_t startOffset, size_t &encodeLen) override;
43 
44     int32_t Pack(PkgStreamPtr inStream, size_t startOffset, size_t &encodeLen) override;
45 
46     int32_t Unpack(PkgStreamPtr outStream) override;
47 
48     int32_t DecodeHeader(const PkgBuffer &buffer, size_t, size_t, size_t &decodeLen) override;
49 
50 private:
51     Lz4FileInfo fileInfo_ {};
52 };
53 
54 class Lz4PkgFile : public PkgFile {
55 public:
Lz4PkgFile(PkgManager::PkgManagerPtr manager,PkgStreamPtr stream)56     explicit Lz4PkgFile(PkgManager::PkgManagerPtr manager, PkgStreamPtr stream)
57         : PkgFile(manager, stream, PkgFile::PKG_TYPE_LZ4)
58     {
59         pkgInfo_.signMethod = PKG_SIGN_METHOD_RSA;
60         pkgInfo_.digestMethod = PKG_DIGEST_TYPE_SHA256;
61     }
~Lz4PkgFile()62     ~Lz4PkgFile() override {}
63 
64     int32_t AddEntry(const PkgManager::FileInfoPtr file, const PkgStreamPtr inStream) override;
65 
66     int32_t SavePackage(size_t &offset) override;
67 
68     int32_t LoadPackage(std::vector<std::string> &fileNames, VerifyFunction verifier = nullptr) override;
69 
70 private:
71     PkgInfo pkgInfo_ {};
72     size_t currentOffset_ {0};
73 };
74 } // namespace Hpackage
75 #endif // LZ4_PKG_FILE_H