1 /* 2 * Copyright (c) 2022-2024 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_OHOS_DM_CONFIG_MANAGER_H 17 #define OHOS_OHOS_DM_CONFIG_MANAGER_H 18 19 #include <cstdlib> 20 #include <map> 21 #include <memory> 22 #if !defined(__LITEOS_M__) 23 #include <mutex> 24 #endif 25 #include <set> 26 #include <string> 27 #include <vector> 28 29 #include "authentication.h" 30 #include "crypto_adapter.h" 31 #include "decision_adapter.h" 32 #include "dm_single_instance.h" 33 34 namespace OHOS { 35 namespace DistributedHardware { 36 typedef struct { 37 std::string name; 38 std::string type; 39 std::string version; 40 std::string funcName; 41 std::string soName; 42 std::string soPath; 43 } AdapterSoLoadInfo; 44 45 typedef struct { 46 int32_t authType; 47 std::string name; 48 std::string type; 49 std::string version; 50 std::string funcName; 51 std::string soName; 52 std::string soPath; 53 } AuthSoLoadInfo; 54 55 class DmConfigManager final { 56 DM_DECLARE_SINGLE_INSTANCE_BASE(DmConfigManager); 57 58 public: 59 ~DmConfigManager(); 60 61 /** 62 * @tc.name: DmConfigManager::GetAllAuthType 63 * @tc.desc: Get All AuthType of the DeviceManager Config Manager 64 * @tc.type: FUNC 65 */ 66 void GetAllAuthType(std::vector<std::string> &allAuthType); 67 std::shared_ptr<ICryptoAdapter> GetCryptoAdapter(const std::string &soName); 68 69 /** 70 * @tc.name: DmConfigManager::GetAuthAdapter 71 * @tc.desc: Get Auth Adapter of the DeviceManager Config Manager 72 * @tc.type: FUNC 73 */ 74 void GetAuthAdapter(std::map<int32_t, std::shared_ptr<IAuthentication>> &authAdapter); 75 76 private: 77 DmConfigManager(); 78 void ParseAdapterConfig(); 79 void ParseAuthConfig(); 80 81 private: 82 #if !defined(__LITEOS_M__) 83 std::mutex authAdapterMutex_; 84 std::mutex cryptoAdapterMutex_; 85 #endif 86 std::map<int32_t, AuthSoLoadInfo> soAuthLoadInfo_; 87 std::map<std::string, AdapterSoLoadInfo> soAdapterLoadInfo_; 88 std::map<std::string, std::shared_ptr<ICryptoAdapter>> cryptoAdapterPtr_; 89 }; 90 } // namespace DistributedHardware 91 } // namespace OHOS 92 #endif // OHOS_OHOS_DM_CONFIG_MANAGER_H 93