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 AUTH_RESOURCE_POOL_H 17 #define AUTH_RESOURCE_POOL_H 18 19 #include "buffer.h" 20 #include "linked_list.h" 21 22 #ifdef __cplusplus 23 extern "C" { 24 #endif 25 26 #define PUBLIC_KEY_LEN 32 27 #define INVALID_EXECUTOR_INDEX 0 28 29 typedef enum ExecutorRole { 30 COLLECTOR = 1, 31 VERIFIER = 2, 32 ALL_IN_ONE = 3, 33 } ExecutorRole; 34 35 typedef struct ExecutorInfoHal { 36 uint64_t executorIndex; 37 uint32_t authType; 38 uint32_t executorSensorHint; 39 uint32_t executorRole; 40 uint32_t executorMatcher; 41 uint32_t esl; 42 uint8_t pubKey[PUBLIC_KEY_LEN]; 43 } ExecutorInfoHal; 44 45 typedef enum ExecutorConditionTag { 46 EXECUTOR_CONDITION_INDEX = 1, 47 EXECUTOR_CONDITION_AUTH_TYPE = 2, // 1 << 1 48 EXECUTOR_CONDITION_SENSOR_HINT = 4, // 1 << 2 49 EXECUTOR_CONDITION_ROLE = 8, // 1 << 3 50 EXECUTOR_CONDITION_MATCHER = 16, // 1 << 4 51 } ExecutorConditionTag; 52 53 typedef struct ExecutorCondition { 54 uint64_t conditonFactor; 55 uint64_t executorIndex; 56 uint32_t authType; 57 uint32_t executorSensorHint; 58 uint32_t executorRole; 59 uint32_t executorMatcher; 60 } ExecutorCondition; 61 62 ResultCode InitResourcePool(void); 63 void DestroyResourcePool(void); 64 ResultCode RegisterExecutorToPool(ExecutorInfoHal *executorInfo); 65 ResultCode UnregisterExecutorToPool(uint64_t executorIndex); 66 67 LinkedList *QueryExecutor(const ExecutorCondition *condition); 68 ResultCode QueryCollecterMatcher(uint32_t authType, uint32_t executorSensorHint, uint32_t *matcher); 69 uint64_t QueryCredentialExecutorIndex(uint32_t authType, uint32_t executorSensorHint); 70 ExecutorInfoHal *CopyExecutorInfo(ExecutorInfoHal *src); 71 72 void SetExecutorConditionExecutorIndex(ExecutorCondition *condition, uint64_t executorIndex); 73 void SetExecutorConditionAuthType(ExecutorCondition *condition, uint32_t authType); 74 void SetExecutorConditionSensorHint(ExecutorCondition *condition, uint32_t executorSensorHint); 75 void SetExecutorConditionExecutorRole(ExecutorCondition *condition, uint32_t executorRole); 76 void SetExecutorConditionExecutorMatcher(ExecutorCondition *condition, uint32_t executorMatcher); 77 78 #ifdef __cplusplus 79 } 80 #endif 81 82 #endif 83