• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 OHOS_HDI_PIN_AUTH_EXECUTOR_IMPL_H
17 #define OHOS_HDI_PIN_AUTH_EXECUTOR_IMPL_H
18 
19 #include <map>
20 #include <mutex>
21 #include <set>
22 #include <vector>
23 
24 #include "nocopyable.h"
25 #include "thread_pool.h"
26 
27 #include "pin_auth_hdi.h"
28 #include "pin_auth.h"
29 
30 namespace OHOS {
31 namespace HDI {
32 namespace PinAuth {
33 class ExecutorImpl : public IExecutor, public NoCopyable {
34 public:
35     explicit ExecutorImpl(std::shared_ptr<OHOS::UserIam::PinAuth::PinAuth> pinHdi);
36     ~ExecutorImpl() override;
37     int32_t GetExecutorInfo(ExecutorInfo &info) override;
38     int32_t GetTemplateInfo(uint64_t templateId, TemplateInfo &info) override;
39     int32_t OnRegisterFinish(const std::vector<uint64_t> &templateIdList,
40         const std::vector<uint8_t> &frameworkPublicKey, const std::vector<uint8_t> &extraInfo) override;
41     int32_t OnSetData(uint64_t scheduleId, uint64_t authSubType, const std::vector<uint8_t> &data) override;
42     int32_t Enroll(uint64_t scheduleId, const std::vector<uint8_t> &extraInfo,
43         const sptr<IExecutorCallbackV1_0> &callbackObj) override;
44     int32_t EnrollV1_1(uint64_t scheduleId, const std::vector<uint8_t> &extraInfo,
45         const sptr<IExecutorCallback> &callbackObj) override;
46     int32_t Authenticate(uint64_t scheduleId, uint64_t templateId, const std::vector<uint8_t> &extraInfo,
47         const sptr<IExecutorCallbackV1_0> &callbackObj) override;
48     int32_t AuthenticateV1_1(uint64_t scheduleId, uint64_t templateId, const std::vector<uint8_t> &extraInfo,
49         const sptr<IExecutorCallback> &callbackObj) override;
50     int32_t Delete(uint64_t templateId) override;
51     int32_t Cancel(uint64_t scheduleId) override;
52     int32_t SendCommand(int32_t commandId, const std::vector<uint8_t> &extraInfo,
53         const sptr<IExecutorCallbackV1_0> &callbackObj) override;
54     int32_t GetProperty(const std::vector<uint64_t> &templateIdList, const std::vector<GetPropertyType> &propertyTypes,
55         Property &property) override;
56 
57 private:
58     class ScheduleMap {
59     public:
60         uint32_t AddScheduleInfo(const uint64_t scheduleId, const uint32_t commandId,
61             const sptr<IExecutorCallbackV1_0> callback, const uint64_t templateId,
62             const std::vector<uint8_t> algoParameter);
63         uint32_t GetScheduleInfo(const uint64_t scheduleId, uint32_t &commandId, sptr<IExecutorCallbackV1_0> &callback,
64             uint64_t &templateId, std::vector<uint8_t> &algoParameter);
65         uint32_t DeleteScheduleId(const uint64_t scheduleId);
66 
67     private:
68         struct ScheduleInfo {
69             uint32_t commandId;
70             sptr<IExecutorCallbackV1_0> callback;
71             uint64_t templateId;
72             std::vector<uint8_t> algoParameter;
73         };
74 
75         std::mutex mutex_;
76         std::map<uint64_t, struct ScheduleInfo> scheduleInfo_;
77     };
78 
79 private:
80     void CallError(const sptr<IExecutorCallbackV1_0> &callbackObj, uint32_t errorCode);
81     int32_t AuthPin(uint64_t scheduleId, uint64_t templateId,
82         const std::vector<uint8_t> &data, std::vector<uint8_t> &resultTlv);
83     int32_t AuthenticateInner(uint64_t scheduleId, uint64_t templateId, std::vector<uint8_t> &algoParameter,
84         const sptr<IExecutorCallbackV1_0> &callbackObj);
85     int32_t EnrollInner(uint64_t scheduleId, const std::vector<uint8_t> &extraInfo,
86         const sptr<IExecutorCallbackV1_0> &callbackObj, std::vector<uint8_t> &algoParameter, uint32_t &algoVersion);
87     std::shared_ptr<OHOS::UserIam::PinAuth::PinAuth> pinHdi_;
88     ScheduleMap scheduleMap_;
89     OHOS::ThreadPool threadPool_;
90 };
91 } // PinAuth
92 } // HDI
93 } // OHOS
94 
95 #endif // OHOS_HDI_PIN_AUTH_EXECUTOR_IMPL_H
96