• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 ASSET_SYSTEM_TYPE_H
17 #define ASSET_SYSTEM_TYPE_H
18 
19 /**
20  * @file asset_system_type.h
21  *
22  * @brief Defines the enums, structs, and error codes used in the Asset APIs.
23  *
24  * @since 11
25  */
26 
27 #include <stdbool.h>
28 #include <stdint.h>
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 /**
35  * @brief Enumerates the types of the asset attribute tags.
36  */
37 typedef enum {
38     /**
39      * The asset attribute tag is a Boolean value.
40      */
41     SEC_ASSET_TYPE_BOOL = 0x1 << 28,
42     /**
43      * The asset attribute tag is a number.
44      */
45     SEC_ASSET_TYPE_NUMBER = 0x2 << 28,
46     /**
47      * The asset attribute tag is an array of bytes.
48      */
49     SEC_ASSET_TYPE_BYTES = 0x3 << 28,
50 } AssetTagType;
51 
52 /**
53  * @brief Defines the mask used to obtain the type of the asset attribute tag.
54  */
55 #define SEC_ASSET_TAG_TYPE_MASK (0xF << 28)
56 
57 /**
58  * @brief Enumerates the asset attribute tags.
59  */
60 typedef enum {
61     /**
62      * Sensitive user data in the form of bytes, such as passwords and tokens.
63      */
64     SEC_ASSET_TAG_SECRET = SEC_ASSET_TYPE_BYTES | 0x01,
65     /**
66      * Asset alias (identifier) in the form of bytes.
67      */
68     SEC_ASSET_TAG_ALIAS = SEC_ASSET_TYPE_BYTES | 0x02,
69     /**
70      * Time when the asset is accessible. The value is of the uint32 type, which is a 32-bit unsigned integer.
71      */
72     SEC_ASSET_TAG_ACCESSIBILITY = SEC_ASSET_TYPE_NUMBER | 0x03,
73     /**
74      * A Boolean value indicating whether the asset is available only with a lock screen password.
75      */
76     SEC_ASSET_TAG_REQUIRE_PASSWORD_SET = SEC_ASSET_TYPE_BOOL | 0x04,
77     /**
78      * User authentication type for the asset. The value is of the uint32 type.
79      */
80     SEC_ASSET_TAG_AUTH_TYPE = SEC_ASSET_TYPE_NUMBER | 0x05,
81     /**
82      * Validity period of the user authentication, in seconds. The value is of the uint32 type.
83      */
84     SEC_ASSET_TAG_AUTH_VALIDITY_PERIOD = SEC_ASSET_TYPE_NUMBER | 0x06,
85     /**
86      * Challenge value, in the form of bytes, used for anti-replay during the authentication.
87      */
88     SEC_ASSET_TAG_AUTH_CHALLENGE = SEC_ASSET_TYPE_BYTES | 0x07,
89     /**
90      * Authentication token, in the form of bytes, obtained after a successful user authentication.
91      */
92     SEC_ASSET_TAG_AUTH_TOKEN = SEC_ASSET_TYPE_BYTES | 0x08,
93     /**
94      * Asset synchronization type. The value is of the uint32 type.
95      */
96     SEC_ASSET_TAG_SYNC_TYPE = SEC_ASSET_TYPE_NUMBER | 0x10,
97     /**
98      * A Boolean value indicating whether the asset needs to be stored persistently.
99      * The ohos.permission.STORE_PERSISTENT_DATA permission is required if <b>OH_Asset_Add</b> is called with this tag.
100      *
101      * @permission ohos.permission.STORE_PERSISTENT_DATA
102      */
103     SEC_ASSET_TAG_IS_PERSISTENT = SEC_ASSET_TYPE_BOOL | 0x11,
104     /**
105      * An immutable custom field, in the form of bytes.
106      */
107     SEC_ASSET_TAG_DATA_LABEL_CRITICAL_1 = SEC_ASSET_TYPE_BYTES | 0x20,
108     /**
109      * An immutable custom field, in the form of bytes.
110      */
111     SEC_ASSET_TAG_DATA_LABEL_CRITICAL_2 = SEC_ASSET_TYPE_BYTES | 0x21,
112     /**
113      * An immutable custom field, in the form of bytes.
114      */
115     SEC_ASSET_TAG_DATA_LABEL_CRITICAL_3 = SEC_ASSET_TYPE_BYTES | 0x22,
116     /**
117      * An immutable custom field, in the form of bytes.
118      */
119     SEC_ASSET_TAG_DATA_LABEL_CRITICAL_4 = SEC_ASSET_TYPE_BYTES | 0x23,
120     /**
121      * A mutable custom field, in the form of bytes.
122      */
123     SEC_ASSET_TAG_DATA_LABEL_NORMAL_1 = SEC_ASSET_TYPE_BYTES | 0x30,
124     /**
125      * A mutable custom field, in the form of bytes.
126      */
127     SEC_ASSET_TAG_DATA_LABEL_NORMAL_2 = SEC_ASSET_TYPE_BYTES | 0x31,
128     /**
129      * A mutable custom field, in the form of bytes.
130      */
131     SEC_ASSET_TAG_DATA_LABEL_NORMAL_3 = SEC_ASSET_TYPE_BYTES | 0x32,
132     /**
133      * A mutable custom field, in the form of bytes.
134      */
135     SEC_ASSET_TAG_DATA_LABEL_NORMAL_4 = SEC_ASSET_TYPE_BYTES | 0x33,
136     /**
137      * A mutable custom field, in the form of bytes. The information of a local tag will not be synchronized.
138      */
139     SEC_ASSET_TAG_DATA_LABEL_NORMAL_LOCAL_1 = SEC_ASSET_TYPE_BYTES | 0x34,
140     /**
141      * A mutable custom field, in the form of bytes. The information of a local tag will not be synchronized.
142      */
143     SEC_ASSET_TAG_DATA_LABEL_NORMAL_LOCAL_2 = SEC_ASSET_TYPE_BYTES | 0x35,
144     /**
145      * A mutable custom field, in the form of bytes. The information of a local tag will not be synchronized.
146      */
147     SEC_ASSET_TAG_DATA_LABEL_NORMAL_LOCAL_3 = SEC_ASSET_TYPE_BYTES | 0x36,
148     /**
149      * A mutable custom field, in the form of bytes. The information of a local tag will not be synchronized.
150      */
151     SEC_ASSET_TAG_DATA_LABEL_NORMAL_LOCAL_4 = SEC_ASSET_TYPE_BYTES | 0x37,
152     /**
153      * Return type of the queried asset. The value is of the uint32 type.
154      */
155     SEC_ASSET_TAG_RETURN_TYPE = SEC_ASSET_TYPE_NUMBER | 0x40,
156     /**
157      * Maximum number of assets that can be returned at a time if multiple asset records match the specified conditions.
158      * The value is of the uint32 type.
159      */
160     SEC_ASSET_TAG_RETURN_LIMIT = SEC_ASSET_TYPE_NUMBER | 0x41,
161     /**
162      * Offset that indicates the start asset when multiple asset records are returned. The value is of the uint32 type.
163      */
164     SEC_ASSET_TAG_RETURN_OFFSET = SEC_ASSET_TYPE_NUMBER | 0x42,
165     /**
166      * Sorting order of the assets in the query result. The value is of the uint32 type.
167      */
168     SEC_ASSET_TAG_RETURN_ORDERED_BY = SEC_ASSET_TYPE_NUMBER | 0x43,
169     /**
170      * Policy used to resolve the conflict occurred when an asset is added. The value is of the uint32 type.
171      */
172     SEC_ASSET_TAG_CONFLICT_RESOLUTION = SEC_ASSET_TYPE_NUMBER | 0x44,
173     /**
174      * A tag whose value is a byte array indicating the update time of an Asset.
175      */
176     SEC_ASSET_TAG_UPDATE_TIME = SEC_ASSET_TYPE_BYTES | 0x45,
177     /**
178      * Tag used to store specific user id. The value is of the uint32 type.
179      */
180     SEC_ASSET_TAG_OPERATION_TYPE = SEC_ASSET_TYPE_NUMBER | 0x46,
181     /**
182      * Tag used to store specific user id. The value is of the uint32 type.
183      */
184     SEC_ASSET_TAG_USER_ID = SEC_ASSET_TYPE_NUMBER | 0x47,
185 } AssetTag;
186 
187 /**
188  * @brief Enumerates the result codes used in the ASSET APIs.
189  */
190 typedef enum {
191     /**
192      * The operation is successful.
193      */
194     SEC_ASSET_SUCCESS = 0,
195     /**
196      * The caller does not have the required permission.
197      */
198     SEC_ASSET_PERMISSION_DENIED = 201,
199     /**
200      * The caller not system application.
201      */
202     SEC_ASSET_NOT_SYSTEM_APPLICATION = 202,
203     /**
204      * The parameter is invalid.
205      */
206     SEC_ASSET_INVALID_ARGUMENT = 401,
207     /**
208      * The asset service is unavailable.
209      */
210     SEC_ASSET_SERVICE_UNAVAILABLE = 24000001,
211     /**
212      * The asset is not found.
213      */
214     SEC_ASSET_NOT_FOUND = 24000002,
215     /**
216      * The asset already exists.
217      */
218     SEC_ASSET_DUPLICATED = 24000003,
219     /**
220      * The access to the asset is denied.
221      */
222     SEC_ASSET_ACCESS_DENIED = 24000004,
223     /**
224      * The lock screen status does not match the access control type specified.
225      */
226     SEC_ASSET_STATUS_MISMATCH = 24000005,
227     /**
228      * The system memory is insufficient.
229      */
230     SEC_ASSET_OUT_OF_MEMORY = 24000006,
231     /**
232      * The asset is corrupted.
233      */
234     SEC_ASSET_DATA_CORRUPTED = 24000007,
235     /**
236      * The database operation failed.
237      */
238     SEC_ASSET_DATABASE_ERROR = 24000008,
239     /**
240      * The cryptography operation failed.
241      */
242     SEC_ASSET_CRYPTO_ERROR = 24000009,
243     /**
244      * The inter-process communication (IPC) failed.
245      */
246     SEC_ASSET_IPC_ERROR = 24000010,
247     /**
248      * The Bundle Manager service is abnormal.
249      */
250     SEC_ASSET_BMS_ERROR = 24000011,
251     /**
252      * The Account service is abnormal.
253      */
254     SEC_ASSET_ACCOUNT_ERROR = 24000012,
255     /**
256      * The Access Token service is abnormal.
257      */
258     SEC_ASSET_ACCESS_TOKEN_ERROR = 24000013,
259     /**
260      * The file operation failed.
261      */
262     SEC_ASSET_FILE_OPERATION_ERROR = 24000014,
263     /**
264      * The operation for obtaining the system time failed.
265      */
266     SEC_ASSET_GET_SYSTEM_TIME_ERROR = 24000015,
267     /**
268      * The number of cached assets exceeds the limit.
269      */
270     SEC_ASSET_LIMIT_EXCEEDED = 24000016,
271     /**
272      * The function is not supported.
273      */
274     SEC_ASSET_UNSUPPORTED = 24000017,
275 } AssetResultCode;
276 
277 /**
278  * @brief Enumerates the types of the access control based on the lock screen status.
279  */
280 typedef enum {
281     /**
282      * The asset can be accessed after the device is powered on.
283      */
284     SEC_ASSET_ACCESSIBILITY_DEVICE_POWERED_ON = 0,
285     /**
286      * The asset can be accessed only after the device is unlocked for the first time.
287      */
288     SEC_ASSET_ACCESSIBILITY_DEVICE_FIRST_UNLOCKED = 1,
289     /**
290      * The asset can be accessed only after the device is unlocked.
291      */
292     SEC_ASSET_ACCESSIBILITY_DEVICE_UNLOCKED = 2,
293 } AssetAccessibility;
294 
295 /**
296  * @brief Enumerates the user authentication types supported for assets.
297  */
298 typedef enum {
299     /**
300      * No user authentication is required before the asset is accessed.
301      */
302     SEC_ASSET_AUTH_TYPE_NONE = 0x00,
303     /**
304      * The asset can be accessed if any user authentication (such as PIN, facial, or fingerprint authentication) is
305      * successful.
306      */
307     SEC_ASSET_AUTH_TYPE_ANY = 0xFF,
308 } AssetAuthType;
309 
310 /**
311  * @brief Enumerates the asset synchronization types.
312  */
313 typedef enum {
314     /**
315      * Asset synchronization is not allowed.
316      */
317     SEC_ASSET_SYNC_TYPE_NEVER = 0,
318     /**
319      * Asset synchronization is allowed only on the local device, for example, in data restoration on the local device.
320      */
321     SEC_ASSET_SYNC_TYPE_THIS_DEVICE = 1 << 0,
322     /**
323      * Asset synchronization is allowed only between trusted devices, for example, in the case of cloning.
324      */
325     SEC_ASSET_SYNC_TYPE_TRUSTED_DEVICE = 1 << 1,
326     /**
327      * Asset synchronization is allowed only between trusted devices, for example, in the case of cloning.
328      */
329     SEC_ASSET_SYNC_TYPE_TRUSTED_ACCOUNT = 1 << 2,
330 } AssetSyncType;
331 
332 /**
333  * @brief Enumerates the policies for resolving the conflict (for example, duplicate alias) occurred when
334  * an asset is added.
335  */
336 typedef enum {
337     /**
338      * Overwrite the existing asset.
339      */
340     SEC_ASSET_CONFLICT_OVERWRITE = 0,
341     /**
342      * Throw an exception for the service to perform subsequent processing.
343      */
344     SEC_ASSET_CONFLICT_THROW_ERROR = 1,
345 } AssetConflictResolution;
346 
347 /**
348  * @brief Enumerates the types of the asset query result.
349  */
350 typedef enum {
351     /**
352      * The query result contains the asset in plaintext and its attributes.
353      */
354     SEC_ASSET_RETURN_ALL = 0,
355     /**
356      * The query result contains only the asset attributes.
357      */
358     SEC_ASSET_RETURN_ATTRIBUTES = 1,
359 } AssetReturnType;
360 
361 /**
362  * @brief Enumerates the types of the asset query result.
363  */
364 typedef enum {
365     /**
366      * Trigger Sync.
367      */
368     SEC_ASSET_NEED_SYNC = 0,
369     /**
370      * Logout account to clean cloud flag.
371      */
372     SEC_ASSET_NEED_LOGOUT = 1,
373     /**
374      * Delete cloud data.
375      */
376     SEC_ASSET_NEED_DELETE_CLOUD_DATA = 2,
377 } AssetOperationType;
378 
379 /**
380  * @brief Defines an asset value in the forma of a binary array, that is, a variable-length byte array.
381  */
382 typedef struct {
383     /**
384      * Size of the byte array.
385      */
386     uint32_t size;
387     /**
388      * Pointer to the byte array.
389      */
390     uint8_t *data;
391 } AssetBlob;
392 
393 /**
394  * @brief Defines the value (content) of an asset attribute.
395  */
396 typedef union {
397     /**
398      * Asset of the Boolean type.
399      */
400     bool boolean;
401     /**
402      * Asset of the uint32 type.
403      */
404     uint32_t u32;
405     /**
406      * Asset of the bytes type.
407      */
408     AssetBlob blob;
409 } AssetValue;
410 
411 /**
412  * @brief Defines an asset attribute.
413  */
414 typedef struct {
415     /**
416      * Tag of the asset attribute.
417      */
418     uint32_t tag;
419     /**
420      * Value of the asset attribute.
421      */
422     AssetValue value;
423 } AssetAttr;
424 
425 /**
426  * @brief Represents information about an asset.
427  */
428 typedef struct {
429     /**
430      * Number of asset attributes.
431      */
432     uint32_t count;
433     /**
434      * Pointer to the array of the asset attributes.
435      */
436     AssetAttr *attrs;
437 } AssetResult;
438 
439 /**
440  * @brief Represents information about a set of assets.
441  */
442 typedef struct {
443     /**
444      * Number of assets.
445      */
446     uint32_t count;
447     /**
448      * Pointer to the array of the assets.
449      */
450     AssetResult *results;
451 } AssetResultSet;
452 
453 #ifdef __cplusplus
454 }
455 #endif
456 
457 #endif // ASSET_SYSTEM_TYPE_H