• 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 OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_CHECKER_CHECKER_MANAGER_H
17 #define OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_CHECKER_CHECKER_MANAGER_H
18 #include <vector>
19 #include "visibility.h"
20 #include "concurrent_map.h"
21 namespace OHOS {
22 namespace DistributedData {
23 class CheckerManager {
24 public:
25     static constexpr pid_t ROOT_UID = 0;
26     struct Trust {
27         std::string bundleName;
28         std::string appId;
29         std::string packageName;
30         std::string base64Key;
31         std::string checker;
32     };
33     struct StoreInfo {
34         pid_t uid;
35         uint32_t tokenId;
36         std::string bundleName;
37         std::string storeId;
38     };
39     class Checker {
40     public:
41         virtual void Initialize() = 0;
42         virtual bool SetTrustInfo(const Trust &trust) = 0;
43         virtual std::string GetAppId(const StoreInfo &info) = 0;
44         virtual bool IsValid(const StoreInfo &info) = 0;
45     protected:
46         API_EXPORT ~Checker() = default;
47     };
48     API_EXPORT static CheckerManager &GetInstance();
49     API_EXPORT void RegisterPlugin(const std::string &checker, std::function<Checker *()> getter);
50     API_EXPORT std::string GetAppId(const StoreInfo &info);
51     API_EXPORT bool IsValid(const StoreInfo &info);
52     API_EXPORT void LoadCheckers(std::vector<std::string> &checkers);
53     API_EXPORT Checker *GetChecker(const std::string &checker);
54 private:
55     std::map<std::string, Checker *> checkers_;
56     ConcurrentMap<std::string, std::function<Checker *()>> getters_;
57 };
58 } // namespace DistributedData
59 } // namespace OHOS
60 #endif // OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_CHECKER_CHECKER_MANAGER_H
61