• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef SIGNATRUETOOLS_FS_VERITY_INFO_SEGMENT_H
16 #define SIGNATRUETOOLS_FS_VERITY_INFO_SEGMENT_H
17 
18 #include <vector>
19 #include <string>
20 
21 #include "signature_tools_log.h"
22 #include "fs_verity_descriptor.h"
23 #include "fs_verity_generator.h"
24 
25 namespace OHOS {
26 namespace SignatureTools {
27 
28 class FsVerityInfoSegment {
29 public:
30     static constexpr int FS_VERITY_INFO_SEGMENT_SIZE = 64;
31     FsVerityInfoSegment();
32     FsVerityInfoSegment(int8_t version, int8_t hashAlgorithm, int8_t log2BlockSize);
33     FsVerityInfoSegment(int magic, int8_t version, int8_t hashAlgorithm,
34                         int8_t log2BlockSize, const std::vector<int8_t>& reserved);
35     virtual ~FsVerityInfoSegment();
36     virtual int Size();
37     virtual void ToByteArray(std::vector<int8_t>& ret);
38     static FsVerityInfoSegment FromByteArray(const std::vector<int8_t>& bytes);
39 
40 private:
41     static constexpr int MAGIC = static_cast<int>((0x1E38 << 16) + (0x31AB));;
42     static constexpr int RESERVED_BYTE_ARRAY_LENGTH = 57;
43     int magic = MAGIC;
44     int8_t hashAlgorithm = 0;
45     int8_t version = 0;
46     int8_t log2BlockSize = 0;
47     std::vector<int8_t> reserved;
48 };
49 } // namespace SignatureTools
50 } // namespace OHOS
51 #endif // SIGNATRUETOOLS_FS_VERITY_INFO_SEGMENT_H
52