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 constexpr const char* AUTH_LOAD_JSON_KEY = "devicemanager_auth_components";
37 constexpr const char* ADAPTER_LOAD_JSON_KEY = "devicemanager_adapter_components";
38 constexpr const char* AUTH_JSON_TYPE_KEY = "AUTHENTICATE";
39 constexpr const char* CPYPTO_JSON_TYPE_KEY = "CPYPTO";
40 constexpr const char* DECISION_JSON_TYPE_KEY = "DECISION";
41 
42 typedef struct {
43     std::string name;
44     std::string type;
45     std::string version;
46     std::string funcName;
47     std::string soName;
48     std::string soPath;
49 } AdapterSoLoadInfo;
50 
51 typedef struct {
52     int32_t authType;
53     std::string name;
54     std::string type;
55     std::string version;
56     std::string funcName;
57     std::string soName;
58     std::string soPath;
59 } AuthSoLoadInfo;
60 
61 class DmConfigManager final {
62     DM_DECLARE_SINGLE_INSTANCE_BASE(DmConfigManager);
63 
64 public:
65     ~DmConfigManager();
66 
67     /**
68      * @tc.name: DmConfigManager::GetAllAuthType
69      * @tc.desc: Get All AuthType of the DeviceManager Config Manager
70      * @tc.type: FUNC
71      */
72     void GetAllAuthType(std::vector<std::string> &allAuthType);
73     std::shared_ptr<ICryptoAdapter> GetCryptoAdapter(const std::string &soName);
74 
75     /**
76      * @tc.name: DmConfigManager::GetAuthAdapter
77      * @tc.desc: Get Auth Adapter of the DeviceManager Config Manager
78      * @tc.type: FUNC
79      */
80     void GetAuthAdapter(std::map<int32_t, std::shared_ptr<IAuthentication>> &authAdapter);
81 
82 private:
83     DmConfigManager();
84     void ParseAdapterConfig();
85     void ParseAuthConfig();
86 
87 private:
88 #if !defined(__LITEOS_M__)
89     std::mutex authAdapterMutex_;
90     std::mutex cryptoAdapterMutex_;
91 #endif
92     std::map<int32_t, AuthSoLoadInfo> soAuthLoadInfo_;
93     std::map<std::string, AdapterSoLoadInfo> soAdapterLoadInfo_;
94     std::map<std::string, std::shared_ptr<ICryptoAdapter>> cryptoAdapterPtr_;
95 };
96 } // namespace DistributedHardware
97 } // namespace OHOS
98 #endif // OHOS_OHOS_DM_CONFIG_MANAGER_H
99