1 /* 2 * Copyright (c) 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_HDI_PIN_AUTH_VERIFIER_IMPL_H 17 #define OHOS_HDI_PIN_AUTH_VERIFIER_IMPL_H 18 19 #include <vector> 20 21 #include "nocopyable.h" 22 #include "thread_pool.h" 23 24 #include "defines.h" 25 #include "pin_auth_hdi.h" 26 #include "pin_auth.h" 27 28 namespace OHOS { 29 namespace HDI { 30 namespace PinAuth { 31 class VerifierImpl : public HdiIVerifier, public NoCopyable { 32 public: 33 explicit VerifierImpl(std::shared_ptr<OHOS::UserIam::PinAuth::PinAuth> pinHdi); 34 ~VerifierImpl() override; 35 36 int32_t GetExecutorInfo(OHOS::HDI::PinAuth::V2_1::ExecutorInfo &executorInfo) override; 37 int32_t OnRegisterFinish(const std::vector<uint64_t> &templateIdList, 38 const std::vector<uint8_t> &frameworkPublicKey, const std::vector<uint8_t> &extraInfo) override; 39 int32_t Cancel(uint64_t scheduleId) override; 40 int32_t SendMessage(uint64_t scheduleId, int32_t srcRole, const std::vector<uint8_t> &msg) override; 41 int32_t Authenticate(uint64_t scheduleId, const std::vector<uint64_t> &templateIdList, 42 const std::vector<uint8_t> &extraInfo, const sptr<HdiIExecutorCallback> &callbackObj) override; 43 int32_t NotifyCollectorReady(uint64_t scheduleId) override; 44 45 private: 46 bool IsCurrentSchedule(uint64_t scheduleId); 47 void CancelCurrentAuth(int32_t errorCode = CANCELED); 48 void HandleSchedulerMsg(const std::vector<uint8_t> &msg); 49 void HandleVerifierMsg(uint64_t scheduleId, const std::vector<uint8_t> &msg); 50 51 std::shared_ptr<OHOS::UserIam::PinAuth::PinAuth> pinHdi_; 52 OHOS::ThreadPool threadPool_; 53 std::optional<uint64_t> scheduleId_; 54 sptr<HdiIExecutorCallback> callback_; 55 }; 56 } // PinAuth 57 } // HDI 58 } // OHOS 59 60 #endif // OHOS_HDI_PIN_AUTH_VERIFIER_IMPL_H 61