1 /*
2  * Copyright (c) 2024-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 HKS_CONFIG_PARSER_H
17 #define HKS_CONFIG_PARSER_H
18 
19 #include "hks_type.h"
20 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24 
25 enum HksUpgradeFileTransferUserType {
26     WITH_OWNER = 0,
27     // default user is 100 for current account system policy
28     WITH_USER
29 };
30 
31 // config struct for hap
32 struct HksFileTransferHapConfig {
33     const char *hapName;
34     // enum HksAuthStorageLevel storageType;
35     // enum HksUpgradeFileTransferUserType userType;
36     bool needDe;
37     bool needFrontUser;
38 };
39 
40 // config struct for sa
41 struct HksFileTransferSystemAbilityConfig {
42     uint32_t uid;
43     // enum HksAuthStorageLevel storageType;
44     bool needDe;
45     bool needFrontUser;
46     // enum HksUpgradeFileTransferUserType userType;
47 };
48 
49 // transfer info leading the huks to upgrade
50 struct HksUpgradeFileTransferInfo {
51     bool skipTransfer;
52     bool needDe;
53     bool needFrontUser;
54     // enum HksAuthStorageLevel storageType;
55     // enum HksUpgradeFileTransferUserType userType;
56     uint32_t uid;
57     uint32_t userId;
58 };
59 
60 // match config: file_content => uid + user id + access token id.
61 // match HksFileTransferHapConfig and HksFileTransferSystemAbilityConfig into HksUpgradeFileTransferInfo
62 int32_t HksParseConfig(const char *alias, const struct HksBlob *fileContent, struct HksUpgradeFileTransferInfo *info);
63 
64 int32_t HksMatchConfig(const char *alias, uint32_t uid, uint32_t userId, uint64_t accessTokenId,
65     struct HksUpgradeFileTransferInfo *info);
66 
67 bool HksIsRdbDeKey(const char *alias);
68 
69 #ifdef __cplusplus
70 }
71 #endif
72 
73 #endif // HKS_CONFIG_PARSER_H