• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022-2024 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 IDM_DATABASE_H
17 #define IDM_DATABASE_H
18 
19 #include <stdint.h>
20 
21 #include "adaptor_memory.h"
22 #include "defines.h"
23 #include "idm_common.h"
24 #include "linked_list.h"
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
30 ResultCode InitUserInfoList(void);
31 void DestroyUserInfoList(void);
32 UserInfo *InitUserInfoNode(void);
33 
34 typedef enum CredentialConditionTag {
35     CREDENTIAL_CONDITION_CREDENTIAL_ID = 1,
36     CREDENTIAL_CONDITION_AUTH_TYPE = 2, // 1 << 1
37     CREDENTIAL_CONDITION_TEMPLATE_ID = 4, // 1 << 2
38     CREDENTIAL_CONDITION_SENSOR_HINT = 8, // 1 << 3
39     CREDENTIAL_CONDITION_EXECUTOR_MATCHER = 16, // 1 << 4
40     CREDENTIAL_CONDITION_USER_ID = 32, // 1 << 5
41     CREDENTIAL_CONDITION_NEED_CACHE_PIN = 64, // 1 << 6
42     CREDENTIAL_CONDITION_NEED_ABANDON = 128, // 1 << 7
43     CREDENTIAL_CONDITION_ABANDON = 256, // 1 << 8
44     CREDENTIAL_CONDITION_CACHE_PIN = 512, // 1 << 8
45 } CredentialConditionTag;
46 
47 typedef struct {
48     uint64_t conditionFactor;
49     uint64_t credentialId;
50     uint64_t templateId;
51     uint32_t authType;
52     uint32_t executorSensorHint;
53     uint32_t executorMatcher;
54     int32_t userId;
55 } CredentialCondition;
56 
57 ResultCode GetSecureUid(int32_t userId, uint64_t *secUid);
58 ResultCode GetEnrolledInfo(int32_t userId, EnrolledInfoHal **enrolledInfos, uint32_t *num);
59 ResultCode GetEnrolledInfoAuthType(int32_t userId, uint32_t authType, EnrolledInfoHal *enrolledInfo);
60 ResultCode DeleteUserInfo(int32_t userId, LinkedList **creds);
61 
62 LinkedList *QueryCredentialLimit(const CredentialCondition *limit);
63 ResultCode QueryCredentialUserId(uint64_t credentialId, int32_t *userId);
64 
65 ResultCode AddCredentialInfo(int32_t userId, CredentialInfoHal *credentialInfo, int32_t userType);
66 ResultCode SetPinSubType(int32_t userId, uint64_t pinSubType);
67 ResultCode GetPinSubType(int32_t userId, uint64_t *pinSubType);
68 ResultCode DeleteCredentialInfo(int32_t userId, uint64_t credentialId, CredentialInfoHal *credentialInfo);
69 void ClearCachePin(int32_t userId);
70 
71 void SetCredentialConditionCredentialId(CredentialCondition *condition, uint64_t credentialId);
72 void SetCredentialConditionTemplateId(CredentialCondition *condition, uint64_t templateId);
73 void SetCredentialConditionAuthType(CredentialCondition *condition, uint32_t authType);
74 void SetCredentialConditionExecutorSensorHint(CredentialCondition *condition, uint32_t executorSensorHint);
75 void SetCredentialConditionExecutorMatcher(CredentialCondition *condition, uint32_t executorMatcher);
76 void SetCredentialConditionUserId(CredentialCondition *condition, int32_t userId);
77 void SetCredentialConditionNeedCachePin(CredentialCondition *condition);
78 void SetCredentialConditionNeedAbandonPin(CredentialCondition *condition);
79 void SetCredentialConditionAbandonPin(CredentialCondition *condition);
80 void SetCredentialConditionCachePin(CredentialCondition *condition);
81 ResultCode GetAllExtUserInfo(UserInfoResult *userInfos, uint32_t userInfolen, uint32_t *userInfoCount);
82 ResultCode GetEnrolledState(int32_t userId, uint32_t authType, EnrolledStateHal *enrolledStateHal);
83 ResultCode SaveGlobalConfigParam(GlobalConfigParamHal *param);
84 ResultCode QueryPinExpiredInfo(int64_t *pinExpiredPeriod);
85 ResultCode GetPinExpiredInfo(int32_t userId, PinExpiredInfo *expiredInfo);
86 bool GetEnableStatus(int32_t userId, uint32_t authType);
87 ResultCode QueryCredentialByIdFunc(uint64_t credentialId, LinkedList **creds);
88 ResultCode QueryAbandonCredential(int32_t userId, LinkedList **creds);
89 ResultCode GetCredentialListByAuthType(int32_t userId, uint32_t authType, LinkedList **creds);
90 ResultCode GetCredentialListByCachePin(int32_t userId, LinkedList **creds);
91 ResultCode GetCredentialListByAbandonFlag(int32_t userId, uint32_t authType, LinkedList **creds);
92 ResultCode GetCredentialByUserIdAndCredId(int32_t userId, uint64_t credentialId, CredentialInfoHal *credentialInfo);
93 ResultCode UpdateAbandonResultForReset(int32_t userId, bool *isDelete, CredentialInfoHal *credentialInfo);
94 ResultCode UpdateAbandonResultForUpdate(int32_t userId, bool *isDelete, CredentialInfoHal *credentialInfo);
95 bool IsAbandonCredentialExpired(const CredentialInfoHal *credentialInfo);
96 int64_t CalcCredentialValidPeriod(const CredentialInfoHal *credentialInfo);
97 int64_t GetCredentialValidPeriod(int32_t userId, uint64_t credentialId);
98 ResultCode ClearAbandonExpiredCredential(int32_t userId, CredentialInfoHal *credentialInfo);
99 
100 #ifdef __cplusplus
101 }
102 #endif
103 
104 #endif // IDM_DATABASE_H