• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2023 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 FINGERPRINT_AUTH_EXECUTOR_HDI_H
17 #define FINGERPRINT_AUTH_EXECUTOR_HDI_H
18 
19 #include <cstdint>
20 #include <map>
21 #include <vector>
22 
23 #include "nocopyable.h"
24 
25 #include "fingerprint_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 FingerprintAuth {
33 namespace UserAuth = OHOS::UserIam::UserAuth;
34 class FingerprintAuthExecutorHdi : public std::enable_shared_from_this<FingerprintAuthExecutorHdi>,
35                                    public UserAuth::IAuthExecutorHdi,
36                                    public NoCopyable {
37 public:
38     explicit FingerprintAuthExecutorHdi(sptr<IExecutor> executorProxy);
39     ~FingerprintAuthExecutorHdi() 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 Enroll(uint64_t scheduleId, const UserAuth::EnrollParam &param,
45         const std::shared_ptr<UserAuth::IExecuteCallback> &callbackObj) override;
46     UserAuth::ResultCode Authenticate(uint64_t scheduleId, const UserAuth::AuthenticateParam &param,
47         const std::shared_ptr<UserAuth::IExecuteCallback> &callbackObj) override;
48     UserAuth::ResultCode Identify(uint64_t scheduleId, const UserAuth::IdentifyParam &param,
49         const std::shared_ptr<UserAuth::IExecuteCallback> &callbackObj) override;
50     UserAuth::ResultCode Delete(const std::vector<uint64_t> &templateIdList) override;
51     UserAuth::ResultCode Cancel(uint64_t scheduleId) override;
52     UserAuth::ResultCode SendCommand(UserAuth::PropertyMode commandId, const std::vector<uint8_t> &extraInfo,
53         const std::shared_ptr<UserAuth::IExecuteCallback> &callbackObj) override;
54     UserAuth::ResultCode GetProperty(const std::vector<uint64_t> &templateIdList,
55         const std::vector<UserAuth::Attributes::AttributeKey> &keys, UserAuth::Property &property) override;
56     UserAuth::ResultCode SetCachedTemplates(const std::vector<uint64_t> &templateIdList) override;
57     void OnHdiDisconnect();
58 
59 private:
60     class SaCommandCallback;
61 
62     UserAuth::ResultCode MoveHdiExecutorInfo(ExecutorInfo &in, UserAuth::ExecutorInfo &out);
63     void MoveHdiTemplateInfo(TemplateInfo &in, UserAuth::TemplateInfo &out);
64     void MoveHdiProperty(Property &in, UserAuth::Property &out);
65     UserAuth::ResultCode ConvertCommandId(const UserAuth::PropertyMode in, CommandId &out);
66     UserAuth::ResultCode ConvertAuthType(const AuthType in, UserAuth::AuthType &out);
67     UserAuth::ResultCode ConvertExecutorRole(const ExecutorRole in, UserAuth::ExecutorRole &out);
68     UserAuth::ResultCode ConvertExecutorSecureLevel(const ExecutorSecureLevel in, UserAuth::ExecutorSecureLevel &out);
69     UserAuth::ResultCode ConvertResultCode(const int32_t in);
70     UserAuth::ResultCode ConvertAttributeKeyToPropertyType(const UserAuth::Attributes::AttributeKey in,
71         GetPropertyType &out);
72     UserAuth::ResultCode ConvertAttributeKeyVectorToPropertyType(
73         const std::vector<UserAuth::Attributes::AttributeKey> inVector, std::vector<GetPropertyType> &outVector);
74     UserAuth::ResultCode RegisterSaCommandCallback();
75 
76     sptr<IExecutor> executorProxy_;
77     sptr<SaCommandCallback> saCommandCallback_;
78 };
79 
80 class FingerprintAuthExecutorHdi::SaCommandCallback : public ISaCommandCallback, public NoCopyable {
81 public:
SaCommandCallback(std::shared_ptr<FingerprintAuthExecutorHdi> executorHdi)82     explicit SaCommandCallback(std::shared_ptr<FingerprintAuthExecutorHdi> executorHdi) : executorHdi_(executorHdi) {};
~SaCommandCallback()83     ~SaCommandCallback() override {};
84     int32_t OnSaCommands(const std::vector<SaCommand> &commands) override;
85 
86 private:
87     std::shared_ptr<FingerprintAuthExecutorHdi> executorHdi_;
88 };
89 } // namespace FingerprintAuth
90 } // namespace UserIam
91 } // namespace OHOS
92 
93 #endif // FINGERPRINT_AUTH_EXECUTOR_HDI_H