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_SIGH_HAP_H 1654aa6d63Sopenharmony_ci#define SIGNATRUETOOLS_SIGH_HAP_H 1754aa6d63Sopenharmony_ci#include <limits.h> 1854aa6d63Sopenharmony_ci#include <unordered_map> 1954aa6d63Sopenharmony_ci#include <vector> 2054aa6d63Sopenharmony_ci#include <memory> 2154aa6d63Sopenharmony_ci 2254aa6d63Sopenharmony_ci#include "hap_utils.h" 2354aa6d63Sopenharmony_ci#include "signer_config.h" 2454aa6d63Sopenharmony_ci#include "hap_signer_block_utils.h" 2554aa6d63Sopenharmony_ci#include "securec.h" 2654aa6d63Sopenharmony_ci 2754aa6d63Sopenharmony_cinamespace OHOS { 2854aa6d63Sopenharmony_cinamespace SignatureTools { 2954aa6d63Sopenharmony_ciclass SignHap { 3054aa6d63Sopenharmony_cipublic: 3154aa6d63Sopenharmony_ci static bool Sign(DataSource* contents[], int32_t len, SignerConfig& config, 3254aa6d63Sopenharmony_ci std::vector<OptionalBlock>& optionalBlocks, ByteBuffer& result); 3354aa6d63Sopenharmony_ci static bool ComputeDigests(const DigestParameter& digestParam, DataSource* contents[], int32_t len, 3454aa6d63Sopenharmony_ci const std::vector<OptionalBlock>& optionalBlocks, ByteBuffer& result); 3554aa6d63Sopenharmony_ci 3654aa6d63Sopenharmony_ciprivate: 3754aa6d63Sopenharmony_ci static constexpr int INT_SIZE = 4; 3854aa6d63Sopenharmony_ci static constexpr int CONTENT_VERSION = 2; 3954aa6d63Sopenharmony_ci static constexpr int BLOCK_NUMBER = 1; 4054aa6d63Sopenharmony_ci static constexpr int CONTENT_NUBER = 3; 4154aa6d63Sopenharmony_ci static constexpr int STORED_ENTRY_SO_ALIGNMENT = 4096; 4254aa6d63Sopenharmony_ci static constexpr int BUFFER_LENGTH = 4096; 4354aa6d63Sopenharmony_ci static constexpr int BLOCK_COUNT = 4; 4454aa6d63Sopenharmony_ci static constexpr int BLOCK_MAGIC = 16; 4554aa6d63Sopenharmony_ci static constexpr int BLOCK_VERSION = 4; 4654aa6d63Sopenharmony_ci static constexpr long INIT_OFFSET_LEN = 4L; 4754aa6d63Sopenharmony_ci static constexpr int OPTIONAL_TYPE_SIZE = 4; 4854aa6d63Sopenharmony_ci static constexpr int OPTIONAL_LENGTH_SIZE = 4; 4954aa6d63Sopenharmony_ci static constexpr int OPTIONAL_OFFSET_SIZE = 4; 5054aa6d63Sopenharmony_ci static void ExtractedResult(std::vector<OptionalBlock>& optionalBlocks, ByteBuffer& result, 5154aa6d63Sopenharmony_ci std::unordered_map<int, int>& typeAndOffsetMap); 5254aa6d63Sopenharmony_ci static bool GenerateHapSigningBlock(const std::string& hapSignatureSchemeBlock, 5354aa6d63Sopenharmony_ci std::vector<OptionalBlock>& optionalBlocks, 5454aa6d63Sopenharmony_ci int compatibleVersion, ByteBuffer& result); 5554aa6d63Sopenharmony_ci static void EncodeListOfPairsToByteArray(const DigestParameter& digestParam, 5654aa6d63Sopenharmony_ci const std::vector<std::pair<int32_t, ByteBuffer>>& contentDigests, 5754aa6d63Sopenharmony_ci ByteBuffer& result); 5854aa6d63Sopenharmony_ci}; 5954aa6d63Sopenharmony_ci} // namespace SignatureTools 6054aa6d63Sopenharmony_ci} // namespace OHOS 6154aa6d63Sopenharmony_ci#endif // SIGNATRUETOOLS_SIGH_HAP_H 62