• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 ACCESSTOKEN_DLP_PERMISSION_SET_PARSER_H
17 #define ACCESSTOKEN_DLP_PERMISSION_SET_PARSER_H
18 
19 #include <memory>
20 #include <string>
21 
22 #include "permission_dlp_mode.h"
23 #include "nlohmann/json.hpp"
24 #include "nocopyable.h"
25 
26 namespace OHOS {
27 namespace Security {
28 namespace AccessToken {
29 const std::string CLONE_PERMISSION_CONFIG_FILE = "/system/etc/dlp_permission/clone_app_permission.json";
30 constexpr int32_t MAX_CLONE_PERMISSION_CONFIG_FILE_SIZE = 5 * 1024 * 1024;
31 constexpr size_t MAX_BUFFER_SIZE = 1024;
32 class DlpPermissionSetParser final {
33 public:
34     static DlpPermissionSetParser& GetInstance();
35     virtual ~DlpPermissionSetParser() = default;
36     int32_t Init();
37 
38 private:
DlpPermissionSetParser()39     DlpPermissionSetParser() : ready_(false) {}
40     DISALLOW_COPY_AND_MOVE(DlpPermissionSetParser);
41     int ReadCfgFile(std::string& dlpPermsRawData);
42     void FromJson(const nlohmann::json& jsonObject, std::vector<PermissionDlpMode>& dlpPerms);
43     int32_t ParserDlpPermsRawData(const std::string& dlpPermsRawData,
44         std::vector<PermissionDlpMode>& dlpPerms);
45     void from_json(const nlohmann::json& j, PermissionDlpMode& p);
46     void ProcessDlpPermsInfos(std::vector<PermissionDlpMode>& dlpPerms);
47 
48     bool ready_;
49 };
50 } // namespace AccessToken
51 } // namespace Security
52 } // namespace OHOS
53 #endif // ACCESSTOKEN_DLP_PERMISSION_SET_PARSER_H
54