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_REQUEST_STATE_H
17 #define OHOS_DM_AUTH_REQUEST_STATE_H
18 #include <cstdint>
19 #include <memory>
20 #include <sstream>
21 
22 #include "dm_log.h"
23 namespace OHOS {
24 namespace DistributedHardware {
25 class DmAuthManager;
26 struct DmAuthRequestContext;
27 class AuthRequestState : public std::enable_shared_from_this<AuthRequestState> {
28 public:
~AuthRequestState()29     virtual ~AuthRequestState()
30     {
31         authManager_.reset();
32     };
33     virtual int32_t GetStateType() = 0;
34     virtual int32_t Enter() = 0;
35 
36     /**
37      * @tc.name: AuthRequestState::Leave
38      * @tc.desc: Leave of the Authenticate Request State
39      * @tc.type: FUNC
40      */
41     int32_t Leave();
42 
43     /**
44      * @tc.name: AuthRequestState::TransitionTo
45      * @tc.desc: Transition of the Authenticate Request State
46      * @tc.type: FUNC
47      */
48     int32_t TransitionTo(std::shared_ptr<AuthRequestState> state);
49     /**
50      * @tc.name: AuthRequestState::SetAuthManager
51      * @tc.desc: Set AuthManager of the Authenticate Request State
52      * @tc.type: FUNC
53      */
54     int32_t SetAuthManager(std::shared_ptr<DmAuthManager> authManager);
55     /**
56      * @tc.name: AuthRequestState::SetAuthContext
57      * @tc.desc: Set Auth Context of the Authenticate Request State
58      * @tc.type: FUNC
59      */
60     int32_t SetAuthContext(std::shared_ptr<DmAuthRequestContext> context);
61     std::shared_ptr<DmAuthRequestContext> GetAuthContext();
62 
63 protected:
64     std::weak_ptr<DmAuthManager> authManager_;
65     std::shared_ptr<DmAuthRequestContext> context_;
66 };
67 
68 class AuthRequestInitState : public AuthRequestState {
69 public:
70     /**
71      * @tc.name: AuthRequestInitState::GetStateType
72      * @tc.desc: Get State Type of the Authenticate Request Init State
73      * @tc.type: FUNC
74      */
75     int32_t GetStateType() override;
76     /**
77      * @tc.name: AuthRequestInitState::Enter
78      * @tc.desc: Enter of the Authenticate Request Init State
79      * @tc.type: FUNC
80      */
81     int32_t Enter() override;
82 };
83 
84 class AuthRequestNegotiateState : public AuthRequestState {
85 public:
86     /**
87      * @tc.name: AuthRequestNegotiateState::GetStateType
88      * @tc.desc: Get State Type of the Authenticate Request Negotiate State
89      * @tc.type: FUNC
90      */
91     int32_t GetStateType() override;
92     /**
93      * @tc.name: AuthRequestNegotiateState::Enter
94      * @tc.desc: Enter of the Authenticate Request Negotiate State
95      * @tc.type: FUNC
96      */
97     int32_t Enter() override;
98 };
99 
100 class AuthRequestNegotiateDoneState : public AuthRequestState {
101 public:
102     /**
103      * @tc.name: AuthRequestNegotiateDoneState::GetStateType
104      * @tc.desc: Get State Type of the Authenticate Request Negotiate Done State
105      * @tc.type: FUNC
106      */
107     int32_t GetStateType() override;
108 
109     /**
110      * @tc.name: AuthRequestNegotiateDoneState::Enter
111      * @tc.desc: Enter of the Authenticate Request Negotiate Done State
112      * @tc.type: FUNC
113      */
114     int32_t Enter() override;
115 };
116 
117 class AuthRequestReplyState : public AuthRequestState {
118 public:
119     /**
120      * @tc.name: AuthRequestReplyState::GetStateType
121      * @tc.desc: Get State Type of the AuthRequest Reply State
122      * @tc.type: FUNC
123      */
124     int32_t GetStateType() override;
125 
126     /**
127      * @tc.name: AuthRequestReplyState::Enter
128      * @tc.desc: Enter of the AuthRequest Reply State
129      * @tc.type: FUNC
130      */
131     int32_t Enter() override;
132 };
133 
134 class AuthRequestJoinState : public AuthRequestState {
135 public:
136     /**
137      * @tc.name: AuthRequestJoinState::GetStateType
138      * @tc.desc: Get State Type of the Auth Request Join State
139      * @tc.type: FUNC
140      */
141     int32_t GetStateType() override;
142 
143     /**
144      * @tc.name: AuthRequestJoinState::Enter
145      * @tc.desc: Enter of the Auth Request Join State
146      * @tc.type: FUNC
147      */
148     int32_t Enter() override;
149 };
150 
151 class AuthRequestNetworkState : public AuthRequestState {
152 public:
153     /**
154      * @tc.name: AuthRequestNetworkState::GetStateType
155      * @tc.desc: Get State Type of the AuthRequest Network State
156      * @tc.type: FUNC
157      */
158     int32_t GetStateType() override;
159 
160     /**
161      * @tc.name: AuthRequestNetworkState::Enter
162      * @tc.desc: Enter of the AuthRequest Network State
163      * @tc.type: FUNC
164      */
165     int32_t Enter() override;
166 };
167 
168 class AuthRequestFinishState : public AuthRequestState {
169 public:
170     /**
171      * @tc.name: AuthRequestFinishState::GetStateType
172      * @tc.desc: Get State Type of the Auth Request Finish State
173      * @tc.type: FUNC
174      */
175     int32_t GetStateType() override;
176 
177     /**
178      * @tc.name: AuthRequestFinishState::Enter
179      * @tc.desc: Enter of the Auth Request Finish State
180      * @tc.type: FUNC
181      */
182     int32_t Enter() override;
183 };
184 
185 class AuthRequestCredential : public AuthRequestState {
186 public:
187     int32_t GetStateType() override;
188     int32_t Enter() override;
189 };
190 
191 class AuthRequestCredentialDone : public AuthRequestState {
192 public:
193     int32_t GetStateType() override;
194     int32_t Enter() override;
195 };
196 
197 class AuthRequestDeleteInit : public AuthRequestState {
198 public:
199     int32_t GetStateType() override;
200     int32_t Enter() override;
201 };
202 
203 class AuthRequestSyncDeleteAcl : public AuthRequestState {
204 public:
205     int32_t GetStateType() override;
206     int32_t Enter() override;
207 };
208 
209 class AuthRequestSyncDeleteAclNone : public AuthRequestState {
210 public:
211     int32_t GetStateType() override;
212     int32_t Enter() override;
213 };
214 } // namespace DistributedHardware
215 } // namespace OHOS
216 #endif // OHOS_DM_AUTH_REQUEST_STATE_H
217