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
16#ifndef SIGNATRUETOOLS_SIGN_BIN_H
17#define SIGNATRUETOOLS_SIGN_BIN_H
18
19#include "signer_config.h"
20
21namespace OHOS {
22namespace SignatureTools {
23class SignBin {
24public:
25    static bool Sign(SignerConfig& signerConfig, const std::map<std::string, std::string>& signParams);
26    static std::vector<int8_t> GenerateFileDigest(const std::string& outputFile,
27                                                  const std::string& signAlg);
28
29private:
30    static bool WriteBlockDataToFile(const std::string& inputFile, const std::string& outputFile,
31                                     const std::string& profileFile, const std::string& profileSigned);
32    static bool WriteSignDataToOutputFile(SignerConfig& SignerConfig, const std::string& outputFile,
33                                          const std::string& signAlg);
34    static bool WriteSignHeadDataToOutputFile(const std::string& inputFile, const std::string& outputFile);
35    static bool CheckBinAndProfileLengthIsValid(int64_t binFileLen, int64_t profileDataLen);
36    static bool IsLongOverflowInteger(int64_t num);
37    static bool IsLongOverflowShort(int64_t num);
38    static bool WriteSignedBin(const std::string& inputFile, const std::string& proBlockByte,
39                               const std::string& signBlockByte, const std::string& profileFile,
40                               const std::string& outputFile);
41};
42} // namespace SignatureTools
43} // namespace OHOS
44#endif