1 /*
2  * Copyright (C) 2021 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 HAP_JSON_PARSER_UTILS_H
16 #define HAP_JSON_PARSER_UTILS_H
17 
18 #include <string>
19 #include <unordered_map>
20 #include <vector>
21 
22 #include "cJSON.h"
23 
24 namespace OHOS {
25 namespace Security {
26 namespace Verify {
27 using JsonMap = std::unordered_map<std::string, std::string>;
28 using JsonObjVec = std::vector<cJSON*>;
29 using StringVec = std::vector<std::string>;
30 
31 class JsonParserUtils {
32 public:
33     static bool ReadTrustedRootCAFromJson(cJSON** jsonObj, const std::string& jsonPath, std::string& error);
34     static bool GetJsonString(const cJSON* json, const std::string& key, std::string& value);
35     static bool ParseJsonToObjVec(const cJSON* json, const std::string& key, JsonObjVec& jsonObjVec);
36     static bool GetJsonInt(const cJSON* json, const std::string& key, int& value);
37     static bool GetJsonStringVec(const cJSON* json, const std::string& key, StringVec& value);
38     static void ParseJsonToMap(const cJSON* json, JsonMap& JsonMap);
39 };
40 } // namespace Verify
41 } // namespace Security
42 } // namespace OHOS
43 #endif // HAP_JSON_PARSER_UTILS_H
44