• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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_TYPE_H
17 #define ASSET_TYPE_H
18 
19 /**
20  * @addtogroup AssetType
21  * @{
22  *
23  * @brief Provides the enums, structs, and error codes used in the Asset APIs.
24  *
25  * @since 11
26  */
27 
28 /**
29  * @file asset_type.h
30  *
31  * @brief Defines the enums, structs, and error codes used in the Asset APIs.
32  *
33  * @library libasset_ndk.z.so
34  * @kit AssetStoreKit
35  * @syscap SystemCapability.Security.Asset
36  * @since 11
37  */
38 
39 #include <stdbool.h>
40 #include <stdint.h>
41 
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 
46 /**
47  * @brief Enumerates the types of the asset attribute tags.
48  *
49  * @since 11
50  */
51 typedef enum {
52     /**
53      * The asset attribute tag is a Boolean value.
54      */
55     ASSET_TYPE_BOOL = 0x1 << 28,
56     /**
57      * The asset attribute tag is a number.
58      */
59     ASSET_TYPE_NUMBER = 0x2 << 28,
60     /**
61      * The asset attribute tag is an array of bytes.
62      */
63     ASSET_TYPE_BYTES = 0x3 << 28,
64 } Asset_TagType;
65 
66 /**
67  * @brief Defines the mask used to obtain the type of the asset attribute tag.
68  *
69  * @since 11
70  */
71 #define ASSET_TAG_TYPE_MASK (0xF << 28)
72 
73 /**
74  * @brief Enumerates the asset attribute tags.
75  *
76  * @since 11
77  */
78 typedef enum {
79     /**
80      * Sensitive user data in the form of bytes, such as passwords and tokens.
81      */
82     ASSET_TAG_SECRET = ASSET_TYPE_BYTES | 0x01,
83     /**
84      * Asset alias (identifier) in the form of bytes.
85      */
86     ASSET_TAG_ALIAS = ASSET_TYPE_BYTES | 0x02,
87     /**
88      * Time when the asset is accessible. The value is of the uint32 type, which is a 32-bit unsigned integer.
89      */
90     ASSET_TAG_ACCESSIBILITY = ASSET_TYPE_NUMBER | 0x03,
91     /**
92      * A Boolean value indicating whether the asset is available only with a lock screen password.
93      */
94     ASSET_TAG_REQUIRE_PASSWORD_SET = ASSET_TYPE_BOOL | 0x04,
95     /**
96      * User authentication type for the asset. The value is of the uint32 type.
97      */
98     ASSET_TAG_AUTH_TYPE = ASSET_TYPE_NUMBER | 0x05,
99     /**
100      * Validity period of the user authentication, in seconds. The value is of the uint32 type.
101      */
102     ASSET_TAG_AUTH_VALIDITY_PERIOD = ASSET_TYPE_NUMBER | 0x06,
103     /**
104      * Challenge value, in the form of bytes, used for anti-replay during the authentication.
105      */
106     ASSET_TAG_AUTH_CHALLENGE = ASSET_TYPE_BYTES | 0x07,
107     /**
108      * Authentication token, in the form of bytes, obtained after a successful user authentication.
109      */
110     ASSET_TAG_AUTH_TOKEN = ASSET_TYPE_BYTES | 0x08,
111     /**
112      * Asset synchronization type. The value is of the uint32 type.
113      */
114     ASSET_TAG_SYNC_TYPE = ASSET_TYPE_NUMBER | 0x10,
115     /**
116      * A Boolean value indicating whether the asset needs to be stored persistently.
117      * The ohos.permission.STORE_PERSISTENT_DATA permission is required if <b>OH_Asset_Add</b> is called with this tag.
118      *
119      * @permission ohos.permission.STORE_PERSISTENT_DATA
120      */
121     ASSET_TAG_IS_PERSISTENT = ASSET_TYPE_BOOL | 0x11,
122     /**
123      * An immutable custom field, in the form of bytes.
124      */
125     ASSET_TAG_DATA_LABEL_CRITICAL_1 = ASSET_TYPE_BYTES | 0x20,
126     /**
127      * An immutable custom field, in the form of bytes.
128      */
129     ASSET_TAG_DATA_LABEL_CRITICAL_2 = ASSET_TYPE_BYTES | 0x21,
130     /**
131      * An immutable custom field, in the form of bytes.
132      */
133     ASSET_TAG_DATA_LABEL_CRITICAL_3 = ASSET_TYPE_BYTES | 0x22,
134     /**
135      * An immutable custom field, in the form of bytes.
136      */
137     ASSET_TAG_DATA_LABEL_CRITICAL_4 = ASSET_TYPE_BYTES | 0x23,
138     /**
139      * A mutable custom field, in the form of bytes.
140      */
141     ASSET_TAG_DATA_LABEL_NORMAL_1 = ASSET_TYPE_BYTES | 0x30,
142     /**
143      * A mutable custom field, in the form of bytes.
144      */
145     ASSET_TAG_DATA_LABEL_NORMAL_2 = ASSET_TYPE_BYTES | 0x31,
146     /**
147      * A mutable custom field, in the form of bytes.
148      */
149     ASSET_TAG_DATA_LABEL_NORMAL_3 = ASSET_TYPE_BYTES | 0x32,
150     /**
151      * A mutable custom field, in the form of bytes.
152      */
153     ASSET_TAG_DATA_LABEL_NORMAL_4 = ASSET_TYPE_BYTES | 0x33,
154     /**
155      * A mutable custom field, in the form of bytes. The information of a local tag will not be synchronized.
156      *
157      * @since 12
158      */
159     ASSET_TAG_DATA_LABEL_NORMAL_LOCAL_1 = ASSET_TYPE_BYTES | 0x34,
160     /**
161      * A mutable custom field, in the form of bytes. The information of a local tag will not be synchronized.
162      *
163      * @since 12
164      */
165     ASSET_TAG_DATA_LABEL_NORMAL_LOCAL_2 = ASSET_TYPE_BYTES | 0x35,
166     /**
167      * A mutable custom field, in the form of bytes. The information of a local tag will not be synchronized.
168      *
169      * @since 12
170      */
171     ASSET_TAG_DATA_LABEL_NORMAL_LOCAL_3 = ASSET_TYPE_BYTES | 0x36,
172     /**
173      * A mutable custom field, in the form of bytes. The information of a local tag will not be synchronized.
174      *
175      * @since 12
176      */
177     ASSET_TAG_DATA_LABEL_NORMAL_LOCAL_4 = ASSET_TYPE_BYTES | 0x37,
178     /**
179      * Return type of the queried asset. The value is of the uint32 type.
180      */
181     ASSET_TAG_RETURN_TYPE = ASSET_TYPE_NUMBER | 0x40,
182     /**
183      * Maximum number of assets that can be returned at a time if multiple asset records match the specified conditions.
184      * The value is of the uint32 type.
185      */
186     ASSET_TAG_RETURN_LIMIT = ASSET_TYPE_NUMBER | 0x41,
187     /**
188      * Offset that indicates the start asset when multiple asset records are returned. The value is of the uint32 type.
189      */
190     ASSET_TAG_RETURN_OFFSET = ASSET_TYPE_NUMBER | 0x42,
191     /**
192      * Sorting order of the assets in the query result. The value is of the uint32 type.
193      */
194     ASSET_TAG_RETURN_ORDERED_BY = ASSET_TYPE_NUMBER | 0x43,
195     /**
196      * Policy used to resolve the conflict occurred when an asset is added. The value is of the uint32 type.
197      */
198     ASSET_TAG_CONFLICT_RESOLUTION = ASSET_TYPE_NUMBER | 0x44,
199     /**
200      * A tag whose value is a byte array indicating the update time of an Asset.
201      *
202      * @since 12
203      */
204     ASSET_TAG_UPDATE_TIME = ASSET_TYPE_BYTES | 0x45,
205     /**
206      * A tag whose value is the uint32 type indicating the additional action.
207      *
208      * @since 12
209      */
210     ASSET_TAG_OPERATION_TYPE = ASSET_TYPE_NUMBER | 0x46,
211 } Asset_Tag;
212 
213 /**
214  * @brief Enumerates the result codes used in the ASSET APIs.
215  *
216  * @since 11
217  */
218 typedef enum {
219     /** @error The operation is successful. */
220     ASSET_SUCCESS = 0,
221     /** @error The caller doesn't have the permission. */
222     ASSET_PERMISSION_DENIED = 201,
223     /** @error The parameter is invalid. */
224     ASSET_INVALID_ARGUMENT = 401,
225     /** @error The ASSET service is unavailable. */
226     ASSET_SERVICE_UNAVAILABLE = 24000001,
227     /** @error The asset is not found. */
228     ASSET_NOT_FOUND = 24000002,
229     /** @error The asset already exists. */
230     ASSET_DUPLICATED = 24000003,
231     /** @error Access to the asset is denied. */
232     ASSET_ACCESS_DENIED = 24000004,
233     /** @error The screen lock status does not match. */
234     ASSET_STATUS_MISMATCH = 24000005,
235     /** @error Insufficient memory. */
236     ASSET_OUT_OF_MEMORY = 24000006,
237     /** @error The asset is corrupted. */
238     ASSET_DATA_CORRUPTED = 24000007,
239     /** @error The database operation failed. */
240     ASSET_DATABASE_ERROR = 24000008,
241     /** @error The cryptography operation failed. */
242     ASSET_CRYPTO_ERROR = 24000009,
243     /** @error IPC failed. */
244     ASSET_IPC_ERROR = 24000010,
245     /** @error Calling the Bundle Manager service failed. */
246     ASSET_BMS_ERROR = 24000011,
247     /** @error Calling the OS Account service failed. */
248     ASSET_ACCOUNT_ERROR = 24000012,
249     /** @error Calling the Access Token service failed. */
250     ASSET_ACCESS_TOKEN_ERROR = 24000013,
251     /** @error The file operation failed. */
252     ASSET_FILE_OPERATION_ERROR = 24000014,
253     /** @error Getting the system time failed. */
254     ASSET_GET_SYSTEM_TIME_ERROR = 24000015,
255     /** @error The cache exceeds the limit. */
256     ASSET_LIMIT_EXCEEDED = 24000016,
257     /** @error The capability is not supported. */
258     ASSET_UNSUPPORTED = 24000017,
259 } Asset_ResultCode;
260 
261 /**
262  * @brief Enumerates the types of the access control based on the lock screen status.
263  *
264  * @since 11
265  */
266 typedef enum {
267     /**
268      * The asset can be accessed after the device is powered on.
269      */
270     ASSET_ACCESSIBILITY_DEVICE_POWERED_ON = 0,
271     /**
272      * The asset can be accessed only after the device is unlocked for the first time.
273      */
274     ASSET_ACCESSIBILITY_DEVICE_FIRST_UNLOCKED = 1,
275     /**
276      * The asset can be accessed only after the device is unlocked.
277      */
278     ASSET_ACCESSIBILITY_DEVICE_UNLOCKED = 2,
279 } Asset_Accessibility;
280 
281 /**
282  * @brief Enumerates the user authentication types supported for assets.
283  *
284  * @since 11
285  */
286 typedef enum {
287     /**
288      * No user authentication is required before the asset is accessed.
289      */
290     ASSET_AUTH_TYPE_NONE = 0x00,
291     /**
292      * The asset can be accessed if any user authentication (such as PIN, facial, or fingerprint authentication) is
293      * successful.
294      */
295     ASSET_AUTH_TYPE_ANY = 0xFF,
296 } Asset_AuthType;
297 
298 /**
299  * @brief Enumerates the asset synchronization types.
300  *
301  * @since 11
302  */
303 typedef enum {
304     /**
305      * Asset synchronization is not allowed.
306      */
307     ASSET_SYNC_TYPE_NEVER = 0,
308     /**
309      * Asset synchronization is allowed only on the local device, for example, in data restoration on the local device.
310      */
311     ASSET_SYNC_TYPE_THIS_DEVICE = 1 << 0,
312     /**
313      * Asset synchronization is allowed only between trusted devices, for example, in the case of cloning.
314      */
315     ASSET_SYNC_TYPE_TRUSTED_DEVICE = 1 << 1,
316     /**
317      * Asset synchronization is allowed only between devices with trusted accounts.
318      *
319      * @since 12
320      */
321     ASSET_SYNC_TYPE_TRUSTED_ACCOUNT = 1 << 2,
322 } Asset_SyncType;
323 
324 /**
325  * @brief Enumerates the policies for resolving the conflict (for example, duplicate alias) occurred when
326  * an asset is added.
327  *
328  * @since 11
329  */
330 typedef enum {
331     /**
332      * Overwrite the existing asset.
333      */
334     ASSET_CONFLICT_OVERWRITE = 0,
335     /**
336      * Throw an exception for the service to perform subsequent processing.
337      */
338     ASSET_CONFLICT_THROW_ERROR = 1,
339 } Asset_ConflictResolution;
340 
341 /**
342  * @brief Enumerates the types of the asset query result.
343  *
344  * @since 11
345  */
346 typedef enum {
347     /**
348      * The query result contains the asset in plaintext and its attributes.
349      */
350     ASSET_RETURN_ALL = 0,
351     /**
352      * The query result contains only the asset attributes.
353      */
354     ASSET_RETURN_ATTRIBUTES = 1,
355 } Asset_ReturnType;
356 
357 /**
358  * @brief Enumerates the types of the additional action.
359  *
360  * @since 12
361  */
362 typedef enum {
363     /**
364      * Synchronization is required during operation.
365      */
366     ASSET_NEED_SYNC = 0,
367     /**
368      * Logout is required during operation.
369      */
370     ASSET_NEED_LOGOUT = 1,
371 } Asset_OperationType;
372 
373 /**
374  * @brief Defines an asset value in the forma of a binary array, that is, a variable-length byte array.
375  *
376  * @since 11
377  */
378 typedef struct {
379     /**
380      * Size of the byte array.
381      */
382     uint32_t size;
383     /**
384      * Pointer to the byte array.
385      */
386     uint8_t *data;
387 } Asset_Blob;
388 
389 /**
390  * @brief Defines the value (content) of an asset attribute.
391  *
392  * @since 11
393  */
394 typedef union {
395     /**
396      * Asset of the Boolean type.
397      */
398     bool boolean;
399     /**
400      * Asset of the uint32 type.
401      */
402     uint32_t u32;
403     /**
404      * Asset of the bytes type.
405      */
406     Asset_Blob blob;
407 } Asset_Value;
408 
409 /**
410  * @brief Defines an asset attribute.
411  *
412  * @since 11
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     Asset_Value value;
423 } Asset_Attr;
424 
425 /**
426  * @brief Represents information about an asset.
427  *
428  * @since 11
429  */
430 typedef struct {
431     /**
432      * Number of asset attributes.
433      */
434     uint32_t count;
435     /**
436      * Pointer to the array of the asset attributes.
437      */
438     Asset_Attr *attrs;
439 } Asset_Result;
440 
441 /**
442  * @brief Represents information about a set of assets.
443  *
444  * @since 11
445  */
446 typedef struct {
447     /**
448      * Number of assets.
449      */
450     uint32_t count;
451     /**
452      * Pointer to the array of the assets.
453      */
454     Asset_Result *results;
455 } Asset_ResultSet;
456 
457 #ifdef __cplusplus
458 }
459 #endif
460 
461 /** @} */
462 #endif // ASSET_TYPE_H