1 /* 2 * Copyright (C) 2025 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 CREDENTIAL_DATA_MANAGER_H 17 #define CREDENTIAL_DATA_MANAGER_H 18 19 #include <stdbool.h> 20 #include "hc_string_vector.h" 21 #include "json_utils.h" 22 23 #define MAX_STRING_LEN 256 24 25 typedef struct { 26 /* unique index*/ 27 HcString credId; 28 /* device */ 29 HcString deviceId; 30 HcString peerUserSpaceId; 31 uint8_t subject; 32 /* user */ 33 HcString userId; 34 uint8_t issuer; 35 /* key */ 36 uint8_t credType; 37 uint8_t keyFormat; 38 uint8_t algorithmType; 39 uint8_t proofType; 40 /* access permission*/ 41 StringVector authorizedAccountList; 42 StringVector authorizedAppList; 43 StringVector authorizedDeviceList; 44 uint8_t authorizedScope; 45 HcString credOwner; 46 int32_t ownerUid; 47 /* extention info*/ 48 HcString extendInfo; 49 } Credential; 50 DECLARE_HC_VECTOR(CredentialVec, Credential*) 51 52 typedef struct { 53 const char *credId; 54 const char *deviceId; 55 const char *peerUserSpaceId; 56 uint8_t subject; 57 const char *userId; 58 uint8_t issuer; 59 uint8_t credType; 60 uint8_t keyFormat; 61 uint8_t algorithmType; 62 uint8_t proofType; 63 uint8_t authorizedScope; 64 const char *credOwner; 65 int32_t ownerUid; 66 } QueryCredentialParams; 67 68 #ifdef __cplusplus 69 extern "C" { 70 #endif 71 72 int32_t InitCredDatabase(void); 73 void DestroyCredDatabase(void); 74 75 int32_t AddCredToDb(int32_t osAccountId, const Credential *credential); 76 int32_t DelCredential(int32_t osAccountId, const QueryCredentialParams *delParams); 77 int32_t QueryCredentials(int32_t osAccountId, const QueryCredentialParams *queryParams, 78 CredentialVec *vec); 79 int32_t SaveOsAccountCredDb(int32_t osAccountId); 80 81 Credential *DeepCopyCredential(const Credential *credential); 82 83 QueryCredentialParams InitQueryCredentialParams(void); 84 int32_t GenerateReturnCredInfo(const Credential *credential, CJson *returnJson); 85 86 Credential *CreateCredential(void); 87 void DestroyCredential(Credential *groupEntry); 88 89 CredentialVec CreateCredentialVec(void); 90 void ClearCredentialVec(CredentialVec *vec); 91 92 #ifdef __cplusplus 93 } 94 #endif 95 #endif 96