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 PIN_AUTH_ALL_IN_ONE_HDI_H 17 #define PIN_AUTH_ALL_IN_ONE_HDI_H 18 19 #include <cstdint> 20 #include <mutex> 21 #include <optional> 22 #include <vector> 23 24 #include "iam_executor_framework_types.h" 25 #include "iam_executor_iauth_executor_hdi.h" 26 #include "iam_executor_iexecute_callback.h" 27 #include "nocopyable.h" 28 #include "pin_auth_hdi.h" 29 30 namespace OHOS { 31 namespace UserIam { 32 namespace PinAuth { 33 class PinAuthAllInOneHdi : public std::enable_shared_from_this<PinAuthAllInOneHdi>, 34 public UserAuth::IAuthExecutorHdi, public NoCopyable { 35 public: 36 explicit PinAuthAllInOneHdi(const sptr<IAllInOneExecutor> &allInOneProxy); 37 ~PinAuthAllInOneHdi() override = default; 38 39 UserAuth::ResultCode GetExecutorInfo(UserAuth::ExecutorInfo &info) override; 40 UserAuth::ResultCode OnRegisterFinish(const std::vector<uint64_t> &templateIdList, 41 const std::vector<uint8_t> &frameworkPublicKey, const std::vector<uint8_t> &extraInfo) override; 42 UserAuth::ResultCode SendMessage(uint64_t scheduleId, int32_t srcRole, const std::vector<uint8_t> &msg) override; 43 UserAuth::ResultCode Enroll(uint64_t scheduleId, const UserAuth::EnrollParam ¶m, 44 const std::shared_ptr<UserAuth::IExecuteCallback> &callbackObj) override; 45 UserAuth::ResultCode Authenticate(uint64_t scheduleId, const UserAuth::AuthenticateParam ¶m, 46 const std::shared_ptr<UserAuth::IExecuteCallback> &callbackObj) override; 47 UserAuth::ResultCode OnSetData(uint64_t scheduleId, uint64_t authSubType, const std::vector<uint8_t> &data, 48 int32_t errorCode); 49 UserAuth::ResultCode Delete(const std::vector<uint64_t> &templateIdList) override; 50 UserAuth::ResultCode Cancel(uint64_t scheduleId) override; 51 UserAuth::ResultCode GetProperty(const std::vector<uint64_t> &templateIdList, 52 const std::vector<UserAuth::Attributes::AttributeKey> &keys, UserAuth::Property &property) override; 53 54 private: 55 void MoveHdiProperty(Property &in, UserAuth::Property &out); 56 UserAuth::ResultCode ConvertAttributeKeyToPropertyType(const UserAuth::Attributes::AttributeKey in, int32_t &out); 57 UserAuth::ResultCode ConvertAttributeKeyVectorToPropertyType( 58 const std::vector<UserAuth::Attributes::AttributeKey> inVector, 59 std::vector<int32_t> &outVector); 60 void SetAuthType(int32_t authType); 61 std::optional<int32_t> GetAuthType(); 62 63 sptr<IAllInOneExecutor> allInOneProxy_ {nullptr}; 64 std::optional<int32_t> authType_ {std::nullopt}; 65 std::mutex mutex_; 66 }; 67 } // namespace PinAuth 68 } // namespace UserIam 69 } // namespace OHOS 70 71 #endif // PIN_AUTH_ALL_IN_ONE_HDI_H