1 /*
2  * Copyright (c) 2021-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_NATIVE_TOKEN_RECEPTOR_H
17 #define ACCESSTOKEN_NATIVE_TOKEN_RECEPTOR_H
18 
19 #include <memory>
20 #include <string>
21 
22 #include "native_token_info_inner.h"
23 
24 #include "access_token.h"
25 #include "nlohmann/json.hpp"
26 #include "nocopyable.h"
27 #include "permission_policy_set.h"
28 #include "permission_state_full.h"
29 
30 namespace OHOS {
31 namespace Security {
32 namespace AccessToken {
33 const std::string NATIVE_TOKEN_CONFIG_FILE = "/data/service/el0/access_token/nativetoken.json";
34 constexpr int MAX_NATIVE_CONFIG_FILE_SIZE = 5 * 1024 * 1024; // 5M
35 constexpr size_t BUFFER_SIZE = 1024;
36 class NativeTokenReceptor final {
37 public:
38     static NativeTokenReceptor& GetInstance();
39     virtual ~NativeTokenReceptor() = default;
40     int Init();
41 
42 private:
NativeTokenReceptor()43     NativeTokenReceptor() {}
44     DISALLOW_COPY_AND_MOVE(NativeTokenReceptor);
45     int ReadCfgFile(std::string &nativeRawData);
46     void FromJson(const nlohmann::json &jsonObject,
47         std::vector<std::shared_ptr<NativeTokenInfoInner>>& tokenInfos);
48     int32_t ParserNativeRawData(const std::string& nativeRawData,
49         std::vector<std::shared_ptr<NativeTokenInfoInner>>& tokenInfos);
50     void from_json(const nlohmann::json& j, NativeTokenInfo& p);
51 };
52 } // namespace AccessToken
53 } // namespace Security
54 } // namespace OHOS
55 #endif // ACCESSTOKEN_NATIVE_TOKEN_RECEPTOR_H
56