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 #ifndef FACE_AUTH_ALL_IN_ONE_EXECUTOR_HDI_H 17 #define FACE_AUTH_ALL_IN_ONE_EXECUTOR_HDI_H 18 19 #include <cstdint> 20 #include <map> 21 #include <vector> 22 23 #include "nocopyable.h" 24 25 #include "face_auth_hdi.h" 26 #include "iam_executor_framework_types.h" 27 #include "iam_executor_iauth_executor_hdi.h" 28 #include "iam_executor_iexecute_callback.h" 29 30 namespace OHOS { 31 namespace UserIam { 32 namespace FaceAuth { 33 namespace UserAuth = OHOS::UserIam::UserAuth; 34 class FaceAuthAllInOneExecutorHdi : public std::enable_shared_from_this<FaceAuthAllInOneExecutorHdi>, 35 public UserAuth::IAuthExecutorHdi, 36 public NoCopyable { 37 public: 38 explicit FaceAuthAllInOneExecutorHdi(sptr<IAllInOneExecutor> executorProxy); 39 ~FaceAuthAllInOneExecutorHdi() override = default; 40 41 UserAuth::ResultCode GetExecutorInfo(UserAuth::ExecutorInfo &info) override; 42 UserAuth::ResultCode OnRegisterFinish(const std::vector<uint64_t> &templateIdList, 43 const std::vector<uint8_t> &frameworkPublicKey, const std::vector<uint8_t> &extraInfo) override; 44 UserAuth::ResultCode SendMessage(uint64_t scheduleId, int32_t srcRole, const std::vector<uint8_t> &msg) override; 45 UserAuth::ResultCode Enroll(uint64_t scheduleId, const UserAuth::EnrollParam ¶m, 46 const std::shared_ptr<UserAuth::IExecuteCallback> &callbackObj) override; 47 UserAuth::ResultCode Authenticate(uint64_t scheduleId, const UserAuth::AuthenticateParam ¶m, 48 const std::shared_ptr<UserAuth::IExecuteCallback> &callbackObj) override; 49 UserAuth::ResultCode Identify(uint64_t scheduleId, const UserAuth::IdentifyParam ¶m, 50 const std::shared_ptr<UserAuth::IExecuteCallback> &callbackObj) override; 51 UserAuth::ResultCode Delete(const std::vector<uint64_t> &templateIdList) override; 52 UserAuth::ResultCode Cancel(uint64_t scheduleId) override; 53 UserAuth::ResultCode SendCommand(UserAuth::PropertyMode commandId, const std::vector<uint8_t> &extraInfo, 54 const std::shared_ptr<UserAuth::IExecuteCallback> &callbackObj) override; 55 UserAuth::ResultCode GetProperty(const std::vector<uint64_t> &templateIdList, 56 const std::vector<UserAuth::Attributes::AttributeKey> &keys, UserAuth::Property &property) override; 57 UserAuth::ResultCode SetCachedTemplates(const std::vector<uint64_t> &templateIdList) override; 58 void OnHdiDisconnect(); 59 60 private: 61 class SaCommandCallback; 62 63 UserAuth::ResultCode MoveHdiExecutorInfo(ExecutorInfo &in, UserAuth::ExecutorInfo &out); 64 void MoveHdiProperty(Property &in, UserAuth::Property &out); 65 UserAuth::ResultCode ConvertCommandId(const UserAuth::PropertyMode in, int32_t &out); 66 UserAuth::ResultCode ConvertAuthType(const int32_t in, UserAuth::AuthType &out); 67 UserAuth::ResultCode ConvertExecutorRole(const int32_t in, UserAuth::ExecutorRole &out); 68 UserAuth::ResultCode ConvertExecutorSecureLevel(const int32_t in, UserAuth::ExecutorSecureLevel &out); 69 UserAuth::ResultCode ConvertResultCode(const int32_t in); 70 UserAuth::ResultCode ConvertAttributeKeyToPropertyType(const UserAuth::Attributes::AttributeKey in, int32_t &out); 71 UserAuth::ResultCode ConvertAttributeKeyVectorToPropertyType( 72 const std::vector<UserAuth::Attributes::AttributeKey> inVector, std::vector<int32_t> &outVector); 73 UserAuth::ResultCode RegisterSaCommandCallback(); 74 75 sptr<IAllInOneExecutor> executorProxy_; 76 sptr<SaCommandCallback> saCommandCallback_; 77 }; 78 79 class FaceAuthAllInOneExecutorHdi::SaCommandCallback : public ISaCommandCallback, public NoCopyable { 80 public: SaCommandCallback(std::shared_ptr<FaceAuthAllInOneExecutorHdi> executorHdi)81 explicit SaCommandCallback(std::shared_ptr<FaceAuthAllInOneExecutorHdi> executorHdi) : executorHdi_(executorHdi) {}; ~SaCommandCallback()82 ~SaCommandCallback() override {}; 83 int32_t OnSaCommands(const std::vector<SaCommand> &commands) override; 84 85 private: 86 std::shared_ptr<FaceAuthAllInOneExecutorHdi> executorHdi_; 87 }; 88 } // namespace FaceAuth 89 } // namespace UserIam 90 } // namespace OHOS 91 92 #endif // FACE_AUTH_ALL_IN_ONE_EXECUTOR_HDI_H