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_SIGN_INFO_H 16 #define SIGNATRUETOOLS_SIGN_INFO_H 17 18 #include <vector> 19 #include <string> 20 #include <cstdint> 21 #include <cstdlib> 22 #include <typeinfo> 23 24 #include "signature_tools_log.h" 25 #include "merkle_tree_extension.h" 26 27 namespace OHOS { 28 namespace SignatureTools { 29 30 class SignInfo { 31 public: 32 static constexpr int32_t FLAG_MERKLE_TREE_INCLUDED = 0x1; 33 static constexpr int32_t MAX_EXTENSION_NUM = 1; 34 static constexpr int32_t SIGN_INFO_SIZE_WITHOUT_SIGNATURE = 60; 35 static constexpr int32_t SALT_BUFFER_LENGTH = 32; 36 static constexpr int32_t SIGNATURE_ALIGNMENT = 4; 37 SignInfo(); 38 SignInfo(int32_t saltSize, int32_t flags, int64_t dataSize, 39 const std::vector<int8_t>& salt, const std::vector<int8_t>& sig); 40 SignInfo(int32_t saltSize, 41 int32_t sigSize, 42 int32_t flags, 43 int64_t dataSize, 44 const std::vector<int8_t>& salt, 45 int32_t extensionNum, 46 int32_t extensionOffset, 47 const std::vector<int8_t>& signature, 48 const std::vector<int8_t>& zeroPadding, 49 const std::vector<MerkleTreeExtension*>& extensionList); 50 SignInfo(const SignInfo& other); 51 SignInfo& operator=(const SignInfo& other); 52 virtual ~SignInfo(); 53 static std::vector<MerkleTreeExtension*> ParseMerkleTreeExtension(ByteBuffer* bf, int32_t inExtensionNum); 54 static SignInfo FromByteArray(std::vector<int8_t> bytes); 55 int32_t GetSize(); 56 void AddExtension(MerkleTreeExtension* extension); 57 Extension* GetExtensionByType(int32_t type); 58 int32_t GetExtensionNum(); 59 std::vector<int8_t> GetSignature(); 60 int64_t GetDataSize(); 61 void ToByteArray(std::vector<int8_t> &ret); 62 63 private: 64 int32_t saltSize; 65 int32_t sigSize; 66 int32_t flags; 67 int64_t dataSize; 68 std::vector<int8_t> salt; 69 int32_t extensionNum; 70 int32_t extensionOffset; 71 std::vector<int8_t> signature; 72 std::vector<int8_t> zeroPadding; 73 std::vector<MerkleTreeExtension*> extensionList; 74 }; 75 } // namespace SignatureTools 76 } // namespace OHOS 77 #endif // SIGNATRUETOOLS_ELF_SIGN_BLOCK_H