• 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<IExecutorCallback> &callbackObj) override;
44     int32_t EnrollV1_1(uint64_t scheduleId, const std::vector<uint8_t> &extraInfo,
45         const sptr<IExecutorCallbackV1_1> &callbackObj) override;
46     int32_t Authenticate(uint64_t scheduleId, uint64_t templateId, const std::vector<uint8_t> &extraInfo,
47         const sptr<IExecutorCallback> &callbackObj) override;
48     int32_t AuthenticateV1_1(uint64_t scheduleId, uint64_t templateId, const std::vector<uint8_t> &extraInfo,
49         const sptr<IExecutorCallbackV1_1> &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<IExecutorCallback> &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<IExecutorCallback> callback, const uint64_t templateId, const std::vector<uint8_t> salt);
62         uint32_t GetScheduleInfo(const uint64_t scheduleId, uint32_t &commandId, sptr<IExecutorCallback> &callback,
63             uint64_t &templateId, std::vector<uint8_t> &salt);
64         uint32_t DeleteScheduleId(const uint64_t scheduleId);
65 
66     private:
67         struct ScheduleInfo {
68             uint32_t commandId;
69             sptr<IExecutorCallback> callback;
70             uint64_t templateId;
71             std::vector<uint8_t> salt;
72         };
73 
74         std::mutex mutex_;
75         std::map<uint64_t, struct ScheduleInfo> scheduleInfo_;
76     };
77 
78 private:
79     uint32_t NewSalt(std::vector<uint8_t> &salt);
80     void CallError(const sptr<IExecutorCallback> &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     std::shared_ptr<OHOS::UserIam::PinAuth::PinAuth> pinHdi_;
84     ScheduleMap scheduleMap_;
85     OHOS::ThreadPool threadPool_;
86 };
87 } // PinAuth
88 } // HDI
89 } // OHOS
90 
91 #endif // OHOS_HDI_PIN_AUTH_EXECUTOR_IMPL_H
92