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 IAM_RESOURCE_NODE_H
17 #define IAM_RESOURCE_NODE_H
18 
19 #include <cstdint>
20 #include <memory>
21 #include <vector>
22 
23 #include "co_auth_interface.h"
24 #include "executor_callback_interface.h"
25 #include "iam_common_defines.h"
26 
27 namespace OHOS {
28 namespace UserIam {
29 namespace UserAuth {
30 class ResourceNode {
31 public:
32     using ExecutorRegisterInfo = CoAuthInterface::ExecutorRegisterInfo;
33     virtual ~ResourceNode() = default;
34     virtual uint64_t GetExecutorIndex() const = 0;
35     virtual std::string GetOwnerDeviceId() const = 0;
36     virtual uint32_t GetOwnerPid() const = 0;
37     virtual AuthType GetAuthType() const = 0;
38     virtual ExecutorRole GetExecutorRole() const = 0;
39     virtual uint64_t GetExecutorSensorHint() const = 0;
40     virtual uint64_t GetExecutorMatcher() const = 0;
41     virtual ExecutorSecureLevel GetExecutorEsl() const = 0;
42     virtual std::vector<uint8_t> GetExecutorPublicKey() const = 0;
43     virtual std::string GetExecutorDeviceUdid() const = 0;
44     virtual int32_t BeginExecute(uint64_t scheduleId, const std::vector<uint8_t> &publicKey,
45         const Attributes &command) = 0;
46     virtual int32_t EndExecute(uint64_t scheduleId, const Attributes &command) = 0;
47     virtual int32_t SetProperty(const Attributes &properties) = 0;
48     virtual int32_t GetProperty(const Attributes &condition, Attributes &values) = 0;
49     virtual int32_t SendData(uint64_t scheduleId, const Attributes &data) = 0;
50     virtual void DeleteFromDriver() = 0;
51     virtual void DetachFromDriver() = 0;
52 
53     static std::shared_ptr<ResourceNode> MakeNewResource(const ExecutorRegisterInfo &info,
54         const std::shared_ptr<ExecutorCallbackInterface> &callback, std::vector<uint64_t> &templateIdList,
55         std::vector<uint8_t> &fwkPublicKey);
56 };
57 } // namespace UserAuth
58 } // namespace UserIam
59 } // namespace OHOS
60 #endif // IAM_RESOURCE_NODE_H