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 struct Trust { 26 std::string bundleName; 27 std::string appId; 28 std::string packageName; 29 std::string base64Key; 30 std::string checker; 31 }; 32 using Distrust = Trust; 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 bool SetDistrustInfo(const Distrust &distrust) = 0; 44 virtual std::string GetAppId(const StoreInfo &info) = 0; 45 virtual bool IsValid(const StoreInfo &info) = 0; 46 virtual bool IsDistrust(const StoreInfo &info) = 0; 47 protected: 48 API_EXPORT ~Checker() = default; 49 }; 50 API_EXPORT static CheckerManager &GetInstance(); 51 API_EXPORT void RegisterPlugin(const std::string &checker, std::function<Checker *()> getter); 52 API_EXPORT std::string GetAppId(const StoreInfo &info); 53 API_EXPORT bool IsValid(const StoreInfo &info); 54 API_EXPORT bool IsDistrust(const StoreInfo &info); 55 API_EXPORT void LoadCheckers(std::vector<std::string> &checkers); 56 API_EXPORT Checker *GetChecker(const std::string &checker); 57 private: 58 std::map<std::string, Checker *> checkers_; 59 ConcurrentMap<std::string, std::function<Checker *()>> getters_; 60 }; 61 } // namespace DistributedData 62 } // namespace OHOS 63 #endif // OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_CHECKER_CHECKER_MANAGER_H