• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef IAM_MOCK_IUSER_AUTH_INTERFACE_H
16 #define IAM_MOCK_IUSER_AUTH_INTERFACE_H
17 
18 #include <memory>
19 #include <mutex>
20 
21 #include "singleton.h"
22 
23 #include "hdi_wrapper.h"
24 #include "user_auth_hdi.h"
25 
26 namespace OHOS {
27 namespace UserIam {
28 namespace UserAuth {
29 class MockIUserAuthInterface final : public IUserAuthInterface {
30 public:
31     class Holder;
Init(const std::string & deviceUdid)32     int32_t Init(const std::string &deviceUdid)
33     {
34         return 0;
35     }
36 
AddExecutor(const HdiExecutorRegisterInfo & info,uint64_t & index,std::vector<uint8_t> & publicKey,std::vector<uint64_t> & templateIds)37     int32_t AddExecutor(const HdiExecutorRegisterInfo &info, uint64_t &index,
38         std::vector<uint8_t> &publicKey, std::vector<uint64_t> &templateIds)
39     {
40         return 0;
41     }
42 
DeleteExecutor(uint64_t index)43     int32_t DeleteExecutor(uint64_t index)
44     {
45         return 0;
46     }
47 
OpenSession(int32_t userId,std::vector<uint8_t> & challenge)48     int32_t OpenSession(int32_t userId, std::vector<uint8_t> &challenge)
49     {
50         return 0;
51     }
52 
CloseSession(int32_t userId)53     int32_t CloseSession(int32_t userId)
54     {
55         return 0;
56     }
57 
UpdateEnrollmentResult(int32_t userId,const std::vector<uint8_t> & scheduleResult,HdiEnrollResultInfo & info)58     int32_t UpdateEnrollmentResult(int32_t userId, const std::vector<uint8_t> &scheduleResult,
59         HdiEnrollResultInfo &info)
60     {
61         return 0;
62     }
63 
CancelEnrollment(int32_t userId)64     int32_t CancelEnrollment(int32_t userId)
65     {
66         return 0;
67     }
68 
DeleteCredential(int32_t userId,uint64_t credentialId,const std::vector<uint8_t> & authToken,HdiCredentialOperateResult & operateResult)69     int32_t DeleteCredential(int32_t userId, uint64_t credentialId, const std::vector<uint8_t> &authToken,
70         HdiCredentialOperateResult &operateResult)
71     {
72         return 0;
73     }
74 
GetCredential(int32_t userId,int32_t authType,std::vector<HdiCredentialInfo> & infos)75     int32_t GetCredential(int32_t userId, int32_t authType, std::vector<HdiCredentialInfo> &infos)
76     {
77         return 0;
78     }
79 
GetUserInfo(int32_t userId,uint64_t & secureUid,int32_t & pinSubType,std::vector<HdiEnrolledInfo> & infos)80     int32_t GetUserInfo(int32_t userId, uint64_t &secureUid, int32_t &pinSubType, std::vector<HdiEnrolledInfo> &infos)
81     {
82         return 0;
83     }
84 
DeleteUser(int32_t userId,const std::vector<uint8_t> & authToken,std::vector<HdiCredentialInfo> & deletedInfos,std::vector<uint8_t> & rootSecret)85     int32_t DeleteUser(int32_t userId, const std::vector<uint8_t> &authToken,
86         std::vector<HdiCredentialInfo> &deletedInfos, std::vector<uint8_t> &rootSecret)
87     {
88         return 0;
89     }
90 
EnforceDeleteUser(int32_t userId,std::vector<HdiCredentialInfo> & deletedInfos)91     int32_t EnforceDeleteUser(int32_t userId, std::vector<HdiCredentialInfo> &deletedInfos)
92     {
93         return 0;
94     }
95 
CancelAuthentication(uint64_t contextId)96     int32_t CancelAuthentication(uint64_t contextId)
97     {
98         return 0;
99     }
100 
UpdateIdentificationResult(uint64_t contextId,const std::vector<uint8_t> & scheduleResult,HdiIdentifyResultInfo & info)101     int32_t UpdateIdentificationResult(uint64_t contextId, const std::vector<uint8_t> &scheduleResult,
102         HdiIdentifyResultInfo &info)
103     {
104         return 0;
105     }
106 
CancelIdentification(uint64_t contextId)107     int32_t CancelIdentification(uint64_t contextId)
108     {
109         return 0;
110     }
111 
GetAvailableStatus(int32_t userId,int32_t authType,uint32_t authTrustLevel,int32_t & checkRet)112     int32_t GetAvailableStatus(int32_t userId, int32_t authType, uint32_t authTrustLevel, int32_t &checkRet)
113     {
114         return 0;
115     }
116 
GetValidSolution(int32_t userId,const std::vector<int32_t> & authTypes,uint32_t authTrustLevel,std::vector<int32_t> & validTypes)117     int32_t GetValidSolution(int32_t userId, const std::vector<int32_t>& authTypes,
118         uint32_t authTrustLevel, std::vector<int32_t>& validTypes)
119     {
120         return 0;
121     }
122 
BeginIdentification(uint64_t contextId,int32_t authType,const std::vector<uint8_t> & challenge,uint32_t executorId,HdiScheduleInfo & scheduleInfo)123     int32_t BeginIdentification(uint64_t contextId, int32_t authType, const std::vector<uint8_t> &challenge,
124         uint32_t executorId, HdiScheduleInfo &scheduleInfo)
125     {
126         return 0;
127     }
128 
GetAllUserInfo(std::vector<UserInfo> & userInfos)129     int32_t GetAllUserInfo(std::vector<UserInfo> &userInfos)
130     {
131         return 0;
132     }
133 
GetAllExtUserInfo(std::vector<ExtUserInfo> & userInfos)134     int32_t GetAllExtUserInfo(std::vector<ExtUserInfo> &userInfos)
135     {
136         return 0;
137     }
138 
BeginEnrollment(const std::vector<uint8_t> & authToken,const HdiEnrollParam & param,HdiScheduleInfo & info)139     int32_t BeginEnrollment(const std::vector<uint8_t> &authToken, const HdiEnrollParam &param, HdiScheduleInfo &info)
140     {
141         return 0;
142     }
143 
BeginAuthentication(uint64_t contextId,const HdiAuthParam & param,std::vector<HdiScheduleInfo> & scheduleInfos)144     int32_t BeginAuthentication(uint64_t contextId, const HdiAuthParam &param,
145         std::vector<HdiScheduleInfo> &scheduleInfos)
146     {
147         return 0;
148     }
149 
GetEnrolledState(int32_t userId,int32_t authType,HdiEnrolledState & hdiEnrolledState)150     int32_t GetEnrolledState(int32_t userId, int32_t authType, HdiEnrolledState &hdiEnrolledState)
151     {
152         return 0;
153     }
154 
UpdateAuthenticationResult(uint64_t contextId,const std::vector<uint8_t> & scheduleResult,HdiAuthResultInfo & info,HdiEnrolledState & enrolledState)155     int32_t UpdateAuthenticationResult(uint64_t contextId, const std::vector<uint8_t> &scheduleResult,
156         HdiAuthResultInfo &info, HdiEnrolledState &enrolledState)
157     {
158         return 0;
159     }
160 
CheckReuseUnlockResult(const HdiReuseUnlockParam & reuseParam,HdiReuseUnlockInfo & reuseInfo)161     int32_t CheckReuseUnlockResult(const HdiReuseUnlockParam &reuseParam, HdiReuseUnlockInfo &reuseInfo)
162     {
163         return 0;
164     }
165 
SendMessage(uint64_t scheduleId,int32_t srcRole,const std::vector<uint8_t> & msg)166     int32_t SendMessage(uint64_t scheduleId, int32_t srcRole, const std::vector<uint8_t> &msg)
167     {
168         return 0;
169     }
170 
RegisterMessageCallback(const sptr<HdiIMessageCallback> & messageCallback)171     int32_t RegisterMessageCallback(const sptr<HdiIMessageCallback> &messageCallback)
172     {
173         return 0;
174     }
175 
PrepareRemoteAuth(const std::string & remoteUdid)176     int32_t PrepareRemoteAuth(const std::string &remoteUdid)
177     {
178         return 0;
179     }
180 
GetLocalScheduleFromMessage(const std::string & remoteUdid,const std::vector<uint8_t> & message,HdiScheduleInfo & scheduleInfo)181     int32_t GetLocalScheduleFromMessage(const std::string &remoteUdid, const std::vector<uint8_t> &message,
182         HdiScheduleInfo &scheduleInfo)
183     {
184         return 0;
185     }
186 
GetSignedExecutorInfo(const std::vector<int32_t> & authTypes,int32_t executorRole,const std::string & remoteUdid,std::vector<uint8_t> & signedExecutorInfo)187     int32_t GetSignedExecutorInfo(const std::vector<int32_t> &authTypes, int32_t executorRole,
188         const std::string &remoteUdid, std::vector<uint8_t> &signedExecutorInfo)
189     {
190         return 0;
191     }
192 
SetGlobalConfigParam(const HdiGlobalConfigParam & param)193     int32_t SetGlobalConfigParam(const HdiGlobalConfigParam &param)
194     {
195         return 0;
196     }
197 
GetAuthResultFromMessage(const std::string & remoteUdid,const std::vector<uint8_t> & message,HdiAuthResultInfo & authResultInfo)198     int32_t GetAuthResultFromMessage(const std::string &remoteUdid, const std::vector<uint8_t> &message,
199         HdiAuthResultInfo &authResultInfo)
200     {
201         return 0;
202     }
203 
VerifyAuthToken(const std::vector<uint8_t> & tokenIn,uint64_t allowableDuration,HdiUserAuthTokenPlain & tokenPlainOut,std::vector<uint8_t> & rootSecret)204     int32_t VerifyAuthToken(const std::vector<uint8_t>& tokenIn, uint64_t allowableDuration,
205         HdiUserAuthTokenPlain &tokenPlainOut, std::vector<uint8_t>& rootSecret)
206     {
207         return 0;
208     }
209 
GetCredentialById(uint64_t credentialId,HdiCredentialInfo & info)210     int32_t GetCredentialById(uint64_t credentialId, HdiCredentialInfo &info)
211     {
212         return 0;
213     }
214 
UpdateAbandonResult(int32_t userId,const std::vector<uint8_t> & scheduleResult,std::vector<HdiCredentialInfo> & infos)215     int32_t UpdateAbandonResult(int32_t userId, const std::vector<uint8_t> &scheduleResult,
216         std::vector<HdiCredentialInfo> &infos)
217     {
218         return 0;
219     }
220 
ClearUnavailableCredential(const std::vector<int32_t> & userIds,std::vector<HdiCredentialInfo> & infos)221     int32_t ClearUnavailableCredential(const std::vector<int32_t> &userIds,
222         std::vector<HdiCredentialInfo> &infos)
223     {
224         return 0;
225     }
226 };
227 
228 class MockIUserAuthInterface::Holder : public Singleton<MockIUserAuthInterface::Holder> {
229 public:
230     void Reset();
231     std::shared_ptr<MockIUserAuthInterface> Get();
232 
233 private:
234     std::mutex mutex_;
235     std::shared_ptr<MockIUserAuthInterface> mock_;
236 };
237 } // namespace UserAuth
238 } // namespace UserIam
239 } // namespace OHOS
240 #endif // IAM_MOCK_IUSER_AUTH_INTERFACE_H