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_CMD_UTIL_H
17#define SIGNATRUETOOLS_CMD_UTIL_H
18
19#include <string>
20#include <vector>
21#include <list>
22#include <regex>
23#include <assert.h>
24#include <algorithm>
25
26#include "params.h"
27#include "params_trust_list.h"
28#include "sign_tool_service_impl.h"
29#include "signature_tools_log.h"
30#include "verify_hap_openssl_utils.h"
31
32namespace OHOS {
33namespace SignatureTools {
34class CmdUtil final {
35public:
36    static bool Convert2Params(char** args, const size_t size, const ParamsSharedPtr& param);
37    static bool JudgeAlgType(const std::string& keyAlg);
38    static bool JudgeSize(const int size);
39    static bool JudgeSignAlgType(const std::string& signAlg);
40    static bool VerifyType(const std::string& inputType);
41    static bool VerifyTypes(const std::string& inputType);
42    static bool VerifyType(const std::string& inputType, const std::string& supportTypes);
43    static bool String2Bool(Options* options, const std::string& option);
44    static bool UpdateParamForCheckInFile(Options* options, const std::initializer_list<std::string>& inFileKeys);
45    static bool UpdateParamForCheckOutFile(Options* options, const std::initializer_list<std::string>& outFileKeys);
46    static constexpr int ARGS_MIN_LEN = 2;
47
48private:
49    static int GetCommandParameterKey(const char strChar, std::string& strChars,
50                                    std::vector<std::string>& trustList, std::string& keyStandBy);
51    static bool ValidAndPutParam(const ParamsSharedPtr& params, const std::string& key, char* value);
52    static const std::regex INTEGER_PATTERN;
53};
54} // namespace SignatureTools
55} // namespace OHOS
56#endif
57