• 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_V1_0_EXECUTOR_IMPL_H
17 #define OHOS_HDI_PIN_AUTH_V1_0_EXECUTOR_IMPL_H
18 
19 #include <map>
20 #include <mutex>
21 #include <set>
22 #include <vector>
23 #include "v1_0/iexecutor.h"
24 #include "pin_auth.h"
25 #include "nocopyable.h"
26 
27 namespace OHOS {
28 namespace HDI {
29 namespace PinAuth {
30 namespace V1_0 {
31 class ExecutorImpl : public IExecutor, public NoCopyable {
32 public:
33     explicit ExecutorImpl(std::shared_ptr<OHOS::UserIam::PinAuth::PinAuth> pinHdi);
~ExecutorImpl()34     virtual ~ExecutorImpl() {}
35     int32_t GetExecutorInfo(ExecutorInfo &info) override;
36     int32_t GetTemplateInfo(uint64_t templateId, TemplateInfo &info) override;
37     int32_t OnRegisterFinish(const std::vector<uint64_t> &templateIdList,
38         const std::vector<uint8_t> &frameworkPublicKey, const std::vector<uint8_t> &extraInfo) override;
39     int32_t OnSetData(uint64_t scheduleId, uint64_t authSubType, const std::vector<uint8_t> &data) override;
40     int32_t Enroll(uint64_t scheduleId, const std::vector<uint8_t> &extraInfo,
41         const sptr<IExecutorCallback> &callbackObj) override;
42     int32_t Authenticate(uint64_t scheduleId, uint64_t templateId, const std::vector<uint8_t> &extraInfo,
43         const sptr<IExecutorCallback> &callbackObj) override;
44     int32_t Delete(uint64_t templateId) override;
45     int32_t Cancel(uint64_t scheduleId) override;
46     int32_t SendCommand(int32_t commandId, const std::vector<uint8_t> &extraInfo,
47         const sptr<IExecutorCallback> &callbackObj) override;
48 
49 private:
50     class ScheduleMap {
51     public:
52         uint32_t AddScheduleInfo(const uint64_t scheduleId, const uint32_t commandId,
53             const sptr<IExecutorCallback> callback, const uint64_t templateId, const std::vector<uint8_t> salt);
54         uint32_t GetScheduleInfo(const uint64_t scheduleId, uint32_t &commandId, sptr<IExecutorCallback> &callback,
55             uint64_t &templateId, std::vector<uint8_t> &salt);
56         uint32_t DeleteScheduleId(const uint64_t scheduleId);
57 
58     private:
59         struct ScheduleInfo {
60             uint32_t commandId;
61             sptr<IExecutorCallback> callback;
62             uint64_t templateId;
63             std::vector<uint8_t> salt;
64         };
65 
66         std::mutex mutex_;
67         std::map<uint64_t, struct ScheduleInfo> scheduleInfo_;
68     };
69 
70 private:
71     uint32_t NewSalt(std::vector<uint8_t> &salt);
72     void CallError(const sptr<IExecutorCallback> &callbackObj, const uint32_t errorCode);
73     std::shared_ptr<OHOS::UserIam::PinAuth::PinAuth> pinHdi_;
74     ScheduleMap scheduleMap_;
75 };
76 } // V1_0
77 } // PinAuth
78 } // HDI
79 } // OHOS
80 
81 #endif // OHOS_HDI_PIN_AUTH_V1_0_EXECUTOR_IMPL_H
82