154aa6d63Sopenharmony_ci/* 254aa6d63Sopenharmony_ci * Copyright (c) 2024-2024 Huawei Device Co., Ltd. 354aa6d63Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 454aa6d63Sopenharmony_ci * you may not use this file except in compliance with the License. 554aa6d63Sopenharmony_ci * You may obtain a copy of the License at 654aa6d63Sopenharmony_ci * 754aa6d63Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 854aa6d63Sopenharmony_ci * 954aa6d63Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1054aa6d63Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1154aa6d63Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1254aa6d63Sopenharmony_ci * See the License for the specific language governing permissions and 1354aa6d63Sopenharmony_ci * limitations under the License. 1454aa6d63Sopenharmony_ci */ 1554aa6d63Sopenharmony_ci#ifndef SIGNATRUETOOLS_SIGN_INFO_H 1654aa6d63Sopenharmony_ci#define SIGNATRUETOOLS_SIGN_INFO_H 1754aa6d63Sopenharmony_ci 1854aa6d63Sopenharmony_ci#include <vector> 1954aa6d63Sopenharmony_ci#include <string> 2054aa6d63Sopenharmony_ci#include <cstdint> 2154aa6d63Sopenharmony_ci#include <cstdlib> 2254aa6d63Sopenharmony_ci#include <typeinfo> 2354aa6d63Sopenharmony_ci 2454aa6d63Sopenharmony_ci#include "signature_tools_log.h" 2554aa6d63Sopenharmony_ci#include "merkle_tree_extension.h" 2654aa6d63Sopenharmony_ci 2754aa6d63Sopenharmony_cinamespace OHOS { 2854aa6d63Sopenharmony_cinamespace SignatureTools { 2954aa6d63Sopenharmony_ci 3054aa6d63Sopenharmony_ciclass SignInfo { 3154aa6d63Sopenharmony_cipublic: 3254aa6d63Sopenharmony_ci static constexpr int32_t FLAG_MERKLE_TREE_INCLUDED = 0x1; 3354aa6d63Sopenharmony_ci static constexpr int32_t MAX_EXTENSION_NUM = 1; 3454aa6d63Sopenharmony_ci static constexpr int32_t SIGN_INFO_SIZE_WITHOUT_SIGNATURE = 60; 3554aa6d63Sopenharmony_ci static constexpr int32_t SALT_BUFFER_LENGTH = 32; 3654aa6d63Sopenharmony_ci static constexpr int32_t SIGNATURE_ALIGNMENT = 4; 3754aa6d63Sopenharmony_ci SignInfo(); 3854aa6d63Sopenharmony_ci SignInfo(int32_t saltSize, int32_t flags, int64_t dataSize, 3954aa6d63Sopenharmony_ci const std::vector<int8_t>& salt, const std::vector<int8_t>& sig); 4054aa6d63Sopenharmony_ci SignInfo(int32_t saltSize, 4154aa6d63Sopenharmony_ci int32_t sigSize, 4254aa6d63Sopenharmony_ci int32_t flags, 4354aa6d63Sopenharmony_ci int64_t dataSize, 4454aa6d63Sopenharmony_ci const std::vector<int8_t>& salt, 4554aa6d63Sopenharmony_ci int32_t extensionNum, 4654aa6d63Sopenharmony_ci int32_t extensionOffset, 4754aa6d63Sopenharmony_ci const std::vector<int8_t>& signature, 4854aa6d63Sopenharmony_ci const std::vector<int8_t>& zeroPadding, 4954aa6d63Sopenharmony_ci const std::vector<MerkleTreeExtension*>& extensionList); 5054aa6d63Sopenharmony_ci SignInfo(const SignInfo& other); 5154aa6d63Sopenharmony_ci SignInfo& operator=(const SignInfo& other); 5254aa6d63Sopenharmony_ci virtual ~SignInfo(); 5354aa6d63Sopenharmony_ci static std::vector<MerkleTreeExtension*> ParseMerkleTreeExtension(ByteBuffer* bf, int32_t inExtensionNum); 5454aa6d63Sopenharmony_ci static SignInfo FromByteArray(std::vector<int8_t> bytes); 5554aa6d63Sopenharmony_ci int32_t GetSize(); 5654aa6d63Sopenharmony_ci void AddExtension(MerkleTreeExtension* extension); 5754aa6d63Sopenharmony_ci Extension* GetExtensionByType(int32_t type); 5854aa6d63Sopenharmony_ci int32_t GetExtensionNum(); 5954aa6d63Sopenharmony_ci std::vector<int8_t> GetSignature(); 6054aa6d63Sopenharmony_ci int64_t GetDataSize(); 6154aa6d63Sopenharmony_ci void ToByteArray(std::vector<int8_t> &ret); 6254aa6d63Sopenharmony_ci 6354aa6d63Sopenharmony_ciprivate: 6454aa6d63Sopenharmony_ci int32_t saltSize; 6554aa6d63Sopenharmony_ci int32_t sigSize; 6654aa6d63Sopenharmony_ci int32_t flags; 6754aa6d63Sopenharmony_ci int64_t dataSize; 6854aa6d63Sopenharmony_ci std::vector<int8_t> salt; 6954aa6d63Sopenharmony_ci int32_t extensionNum; 7054aa6d63Sopenharmony_ci int32_t extensionOffset; 7154aa6d63Sopenharmony_ci std::vector<int8_t> signature; 7254aa6d63Sopenharmony_ci std::vector<int8_t> zeroPadding; 7354aa6d63Sopenharmony_ci std::vector<MerkleTreeExtension*> extensionList; 7454aa6d63Sopenharmony_ci}; 7554aa6d63Sopenharmony_ci} // namespace SignatureTools 7654aa6d63Sopenharmony_ci} // namespace OHOS 7754aa6d63Sopenharmony_ci#endif // SIGNATRUETOOLS_ELF_SIGN_BLOCK_H