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 #include "useridm_module.h"
17 #include "useridm_hilog_wrapper.h"
18
19 namespace OHOS {
20 namespace UserIAM {
21 namespace UserIDM {
InsertChallenge(uint64_t challenge)22 bool UserIDMModule::InsertChallenge(uint64_t challenge)
23 {
24 std::lock_guard<std::mutex> idmMutexGuard(mutex_);
25 USERIDM_HILOGI(MODULE_SERVICE, "Data module InsertChallenge start");
26
27 challengeAndScheduleId_.first = challenge;
28
29 return true;
30 }
31
InsertScheduleId(uint64_t scheduleId)32 bool UserIDMModule::InsertScheduleId(uint64_t scheduleId)
33 {
34 std::lock_guard<std::mutex> idmMutexGuard(mutex_);
35 USERIDM_HILOGI(MODULE_SERVICE, "Data module InsertScheduleId start");
36
37 challengeAndScheduleId_.second = scheduleId;
38
39 return true;
40 }
41
DeleteChallenge()42 void UserIDMModule::DeleteChallenge()
43 {
44 std::lock_guard<std::mutex> idmMutexGuard(mutex_);
45 USERIDM_HILOGI(MODULE_SERVICE, "Data module DeleteChallenge start");
46
47 challengeAndScheduleId_.first = 0;
48 }
49
DeleteSessionId()50 void UserIDMModule::DeleteSessionId()
51 {
52 std::lock_guard<std::mutex> idmMutexGuard(mutex_);
53 USERIDM_HILOGI(MODULE_SERVICE, "Data module DeleteSessionId start");
54
55 challengeAndScheduleId_.second = 0;
56 }
57
CleanData()58 void UserIDMModule::CleanData()
59 {
60 std::lock_guard<std::mutex> idmMutexGuard(mutex_);
61 USERIDM_HILOGI(MODULE_SERVICE, "Data module CleanData start");
62
63 challengeAndScheduleId_.first = 0;
64 challengeAndScheduleId_.second = 0;
65 }
66
CheckChallenge(uint64_t & challenge)67 bool UserIDMModule::CheckChallenge(uint64_t& challenge)
68 {
69 std::lock_guard<std::mutex> idmMutexGuard(mutex_);
70 USERIDM_HILOGI(MODULE_SERVICE, "Data module CheckChallenge start");
71 if (challengeAndScheduleId_.first == 0) {
72 USERIDM_HILOGE(MODULE_SERVICE, "no session num");
73 return false;
74 }
75 challenge = challengeAndScheduleId_.first;
76 return true;
77 }
78
CheckScheduleIdIsActive(uint64_t & scheduleId)79 bool UserIDMModule::CheckScheduleIdIsActive(uint64_t& scheduleId)
80 {
81 std::lock_guard<std::mutex> idmMutexGuard(mutex_);
82 USERIDM_HILOGI(MODULE_SERVICE, "Data module CheckScheduleIdIsActive start");
83 bool res = false;
84
85 if (challengeAndScheduleId_.second == 0) {
86 USERIDM_HILOGE(MODULE_SERVICE, "no session num");
87 } else {
88 res = true;
89 scheduleId = challengeAndScheduleId_.second;
90 }
91
92 return res;
93 }
94 } // namespace UserIDM
95 } // namespace UserIAM
96 } // namespace OHOS