1094332d3Sopenharmony_ci/*
2094332d3Sopenharmony_ci * Copyright (C) 2022 Huawei Device Co., Ltd.
3094332d3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4094332d3Sopenharmony_ci * you may not use this file except in compliance with the License.
5094332d3Sopenharmony_ci * You may obtain a copy of the License at
6094332d3Sopenharmony_ci *
7094332d3Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8094332d3Sopenharmony_ci *
9094332d3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10094332d3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11094332d3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12094332d3Sopenharmony_ci * See the License for the specific language governing permissions and
13094332d3Sopenharmony_ci * limitations under the License.
14094332d3Sopenharmony_ci */
15094332d3Sopenharmony_ci
16094332d3Sopenharmony_ci#ifndef AUTH_RESOURCE_POOL_H
17094332d3Sopenharmony_ci#define AUTH_RESOURCE_POOL_H
18094332d3Sopenharmony_ci
19094332d3Sopenharmony_ci#include "buffer.h"
20094332d3Sopenharmony_ci#include "c_array.h"
21094332d3Sopenharmony_ci#include "linked_list.h"
22094332d3Sopenharmony_ci
23094332d3Sopenharmony_ci#ifdef __cplusplus
24094332d3Sopenharmony_ciextern "C" {
25094332d3Sopenharmony_ci#endif
26094332d3Sopenharmony_ci
27094332d3Sopenharmony_ci#define PUBLIC_KEY_LEN 32
28094332d3Sopenharmony_ci#define INVALID_EXECUTOR_INDEX 0
29094332d3Sopenharmony_ci#define CHALLENGE_LEN 32
30094332d3Sopenharmony_ci
31094332d3Sopenharmony_citypedef enum ExecutorRole {
32094332d3Sopenharmony_ci    COLLECTOR = 1,
33094332d3Sopenharmony_ci    VERIFIER = 2,
34094332d3Sopenharmony_ci    ALL_IN_ONE = 3,
35094332d3Sopenharmony_ci} ExecutorRole;
36094332d3Sopenharmony_ci
37094332d3Sopenharmony_citypedef struct ExecutorInfoHal {
38094332d3Sopenharmony_ci    uint64_t executorIndex;
39094332d3Sopenharmony_ci    uint32_t authType;
40094332d3Sopenharmony_ci    uint32_t executorSensorHint;
41094332d3Sopenharmony_ci    uint32_t executorRole;
42094332d3Sopenharmony_ci    uint32_t executorMatcher;
43094332d3Sopenharmony_ci    uint32_t esl;
44094332d3Sopenharmony_ci    uint32_t maxTemplateAcl;
45094332d3Sopenharmony_ci    uint8_t pubKey[PUBLIC_KEY_LEN];
46094332d3Sopenharmony_ci    uint8_t deviceUdid[UDID_LEN];
47094332d3Sopenharmony_ci} ExecutorInfoHal;
48094332d3Sopenharmony_ci
49094332d3Sopenharmony_citypedef enum ExecutorConditionTag {
50094332d3Sopenharmony_ci    EXECUTOR_CONDITION_INDEX = 1,
51094332d3Sopenharmony_ci    EXECUTOR_CONDITION_AUTH_TYPE = 2, // 1 << 1
52094332d3Sopenharmony_ci    EXECUTOR_CONDITION_SENSOR_HINT = 4, // 1 << 2
53094332d3Sopenharmony_ci    EXECUTOR_CONDITION_ROLE = 8, // 1 << 3
54094332d3Sopenharmony_ci    EXECUTOR_CONDITION_MATCHER = 16, // 1 << 4
55094332d3Sopenharmony_ci    EXECUTOR_CONDITION_UDID = 32, // 1 << 5
56094332d3Sopenharmony_ci} ExecutorConditionTag;
57094332d3Sopenharmony_ci
58094332d3Sopenharmony_citypedef struct ExecutorCondition {
59094332d3Sopenharmony_ci    uint64_t conditonFactor;
60094332d3Sopenharmony_ci    uint64_t executorIndex;
61094332d3Sopenharmony_ci    uint32_t authType;
62094332d3Sopenharmony_ci    uint32_t executorSensorHint;
63094332d3Sopenharmony_ci    uint32_t executorRole;
64094332d3Sopenharmony_ci    uint32_t executorMatcher;
65094332d3Sopenharmony_ci    uint8_t deviceUdid[UDID_LEN];
66094332d3Sopenharmony_ci} ExecutorCondition;
67094332d3Sopenharmony_ci
68094332d3Sopenharmony_ciResultCode InitResourcePool(void);
69094332d3Sopenharmony_civoid DestroyResourcePool(void);
70094332d3Sopenharmony_ciResultCode RegisterExecutorToPool(ExecutorInfoHal *executorInfo);
71094332d3Sopenharmony_ciResultCode UnregisterExecutorToPool(uint64_t executorIndex);
72094332d3Sopenharmony_ci
73094332d3Sopenharmony_ciLinkedList *QueryExecutor(const ExecutorCondition *condition);
74094332d3Sopenharmony_ciResultCode QueryCollecterMatcher(uint32_t authType, uint32_t executorSensorHint, uint32_t *matcher);
75094332d3Sopenharmony_ciuint64_t QueryCredentialExecutorIndex(uint32_t authType, uint32_t executorSensorHint);
76094332d3Sopenharmony_ciExecutorInfoHal *CopyExecutorInfo(ExecutorInfoHal *src);
77094332d3Sopenharmony_ci
78094332d3Sopenharmony_civoid SetExecutorConditionExecutorIndex(ExecutorCondition *condition, uint64_t executorIndex);
79094332d3Sopenharmony_civoid SetExecutorConditionAuthType(ExecutorCondition *condition, uint32_t authType);
80094332d3Sopenharmony_civoid SetExecutorConditionSensorHint(ExecutorCondition *condition, uint32_t executorSensorHint);
81094332d3Sopenharmony_civoid SetExecutorConditionExecutorRole(ExecutorCondition *condition, uint32_t executorRole);
82094332d3Sopenharmony_civoid SetExecutorConditionExecutorMatcher(ExecutorCondition *condition, uint32_t executorMatcher);
83094332d3Sopenharmony_civoid SetExecutorConditionDeviceUdid(ExecutorCondition *condition, Uint8Array deviceUdid);
84094332d3Sopenharmony_ci
85094332d3Sopenharmony_ci#ifdef __cplusplus
86094332d3Sopenharmony_ci}
87094332d3Sopenharmony_ci#endif
88094332d3Sopenharmony_ci
89094332d3Sopenharmony_ci#endif
90