• 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_DM_AUTH_MESSAGE_PROCESSOR_H
17 #define OHOS_DM_AUTH_MESSAGE_PROCESSOR_H
18 
19 #include <memory>
20 #include <vector>
21 
22 #include "crypto_adapter.h"
23 #include "dm_auth_manager.h"
24 #include "nlohmann/json.hpp"
25 
26 namespace OHOS {
27 namespace DistributedHardware {
28 class DmAuthManager;
29 struct DmAuthRequestContext;
30 struct DmAuthResponseContext;
31 class ICryptoAdapter;
32 class AuthMessageProcessor {
33 public:
34     explicit AuthMessageProcessor(std::shared_ptr<DmAuthManager> authMgr);
35     ~AuthMessageProcessor();
36     std::vector<std::string> CreateAuthRequestMessage();
37     std::string CreateSimpleMessage(int32_t msgType);
38     int32_t ParseMessage(const std::string &message);
39     void SetRequestContext(std::shared_ptr<DmAuthRequestContext> authRequestContext);
40     void SetResponseContext(std::shared_ptr<DmAuthResponseContext> authResponseContext);
41     std::shared_ptr<DmAuthResponseContext> GetResponseContext();
42     std::shared_ptr<DmAuthRequestContext> GetRequestContext();
43 
44 private:
45     std::string CreateRequestAuthMessage(nlohmann::json &json);
46     void CreateNegotiateMessage(nlohmann::json &json);
47     void CreateSyncGroupMessage(nlohmann::json &json);
48     void CreateResponseAuthMessage(nlohmann::json &json);
49     void ParseAuthResponseMessage(nlohmann::json &json);
50     int32_t ParseAuthRequestMessage(nlohmann::json &json);
51     void ParseNegotiateMessage(const nlohmann::json &json);
52     void ParseRespNegotiateMessage(const nlohmann::json &json);
53     void CreateResponseFinishMessage(nlohmann::json &json);
54     void ParseResponseFinishMessage(nlohmann::json &json);
55 
56 private:
57     std::weak_ptr<DmAuthManager> authMgr_;
58     std::shared_ptr<ICryptoAdapter> cryptoAdapter_;
59     std::shared_ptr<DmAuthRequestContext> authRequestContext_;
60     std::shared_ptr<DmAuthResponseContext> authResponseContext_;
61     std::vector<nlohmann::json> authSplitJsonList_;
62 };
63 } // namespace DistributedHardware
64 } // namespace OHOS
65 #endif // OHOS_DM_AUTH_MESSAGE_PROCESSOR_H
66