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 16 #ifndef OHOS_HDI_PIN_AUTH_ALL_IN_ONE_IMPL_H 17 #define OHOS_HDI_PIN_AUTH_ALL_IN_ONE_IMPL_H 18 19 #include <list> 20 #include <mutex> 21 #include <vector> 22 23 #include "nocopyable.h" 24 #include "thread_pool.h" 25 26 #include "pin_auth_hdi.h" 27 #include "pin_auth.h" 28 29 namespace OHOS { 30 namespace HDI { 31 namespace PinAuth { 32 class AllInOneImpl : public HdiIAllInOneExecutor, public NoCopyable { 33 public: 34 explicit AllInOneImpl(std::shared_ptr<OHOS::UserIam::PinAuth::PinAuth> pinHdi); 35 ~AllInOneImpl() override; 36 37 int32_t GetExecutorInfo(HdiExecutorInfo &info) override; 38 int32_t OnRegisterFinish(const std::vector<uint64_t> &templateIdList, 39 const std::vector<uint8_t> &frameworkPublicKey, const std::vector<uint8_t> &extraInfo) override; 40 int32_t Cancel(uint64_t scheduleId) override; 41 int32_t SendMessage(uint64_t scheduleId, int32_t srcRole, const std::vector<uint8_t>& msg) override; 42 int32_t SetData(uint64_t scheduleId, uint64_t authSubType, const std::vector<uint8_t> &data, 43 int32_t resultCode) override; 44 int32_t Enroll(uint64_t scheduleId, const std::vector<uint8_t> &extraInfo, 45 const sptr<HdiIExecutorCallback> &callbackObj) override; 46 int32_t Authenticate(uint64_t scheduleId, const std::vector<uint64_t>& templateIdList, 47 const std::vector<uint8_t> &extraInfo, const sptr<HdiIExecutorCallback> &callbackObj) override; 48 int32_t Delete(uint64_t templateId) override; 49 int32_t GetProperty(const std::vector<uint64_t> &templateIdList, const std::vector<int32_t> &propertyTypes, 50 HdiProperty &property) override; 51 52 private: 53 struct ScheduleInfo { 54 uint64_t scheduleId{0}; 55 uint32_t commandId{0}; 56 sptr<HdiIExecutorCallback> callback; 57 uint64_t templateId{0}; 58 std::vector<uint8_t> algoParameter; 59 }; 60 61 class ScheduleList { 62 public: 63 bool AddScheduleInfo(const ScheduleInfo &scheduleInfo); 64 bool GetAndDelScheduleInfo(uint64_t scheduleId, ScheduleInfo &scheduleInfo); 65 void DelScheduleInfo(uint64_t scheduleId); 66 private: 67 std::mutex mutex_; 68 std::list<struct ScheduleInfo> scheduleInfoList_; 69 }; 70 71 private: 72 int32_t AuthPin(uint64_t scheduleId, uint64_t templateId, const std::vector<uint8_t> &data, 73 std::vector<uint8_t> &resultTlv); 74 int32_t AuthenticateInner(uint64_t scheduleId, uint64_t templateId, std::vector<uint8_t> &algoParameter, 75 const sptr<HdiIExecutorCallback> &callbackObj); 76 int32_t EnrollInner(uint64_t scheduleId, const std::vector<uint8_t> &extraInfo, 77 const sptr<HdiIExecutorCallback> &callbackObj, std::vector<uint8_t> &algoParameter, uint32_t &algoVersion); 78 79 std::shared_ptr<OHOS::UserIam::PinAuth::PinAuth> pinHdi_; 80 ScheduleList scheduleList_; 81 OHOS::ThreadPool threadPool_; 82 }; 83 } // PinAuth 84 } // HDI 85 } // OHOS 86 87 #endif // OHOS_HDI_PIN_AUTH_ALL_IN_ONE_IMPL_H 88