1dfe32fa1Soh_ci/*
2dfe32fa1Soh_ci * Copyright (c) 2023 Huawei Device Co., Ltd.
3dfe32fa1Soh_ci * Licensed under the Apache License, Version 2.0 (the "License");
4dfe32fa1Soh_ci * you may not use this file except in compliance with the License.
5dfe32fa1Soh_ci * You may obtain a copy of the License at
6dfe32fa1Soh_ci *
7dfe32fa1Soh_ci *    http://www.apache.org/licenses/LICENSE-2.0
8dfe32fa1Soh_ci *
9dfe32fa1Soh_ci * Unless required by applicable law or agreed to in writing, software
10dfe32fa1Soh_ci * distributed under the License is distributed on an "AS IS" BASIS,
11dfe32fa1Soh_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12dfe32fa1Soh_ci * See the License for the specific language governing permissions and
13dfe32fa1Soh_ci * limitations under the License.
14dfe32fa1Soh_ci */
15dfe32fa1Soh_ci
16dfe32fa1Soh_ci#ifndef ASSET_API_H
17dfe32fa1Soh_ci#define ASSET_API_H
18dfe32fa1Soh_ci
19dfe32fa1Soh_ci#include <stdint.h>
20dfe32fa1Soh_ci#include <stdlib.h>
21dfe32fa1Soh_ci
22dfe32fa1Soh_ci#include "asset_type.h"
23dfe32fa1Soh_ci
24dfe32fa1Soh_ci/**
25dfe32fa1Soh_ci * @addtogroup AssetApi
26dfe32fa1Soh_ci * @{
27dfe32fa1Soh_ci *
28dfe32fa1Soh_ci * @brief Provides APIs for storing and managing short sensitive data of users, including adding, deleting, updating,
29dfe32fa1Soh_ci * and querying the data.
30dfe32fa1Soh_ci * The short sensitive data refers to sensitive data shorter than 1024 bytes, including the user passwords
31dfe32fa1Soh_ci * (accounts/passwords), token data (application credentials), and critical data in plaintext (bank card numbers).
32dfe32fa1Soh_ci *
33dfe32fa1Soh_ci * @since 11
34dfe32fa1Soh_ci */
35dfe32fa1Soh_ci
36dfe32fa1Soh_ci/**
37dfe32fa1Soh_ci * @file asset_api.h
38dfe32fa1Soh_ci *
39dfe32fa1Soh_ci * @brief Declares the APIs for accessing assets.
40dfe32fa1Soh_ci *
41dfe32fa1Soh_ci * @library libasset_ndk.z.so
42dfe32fa1Soh_ci * @kit AssetStoreKit
43dfe32fa1Soh_ci * @syscap SystemCapability.Security.Asset
44dfe32fa1Soh_ci * @since 11
45dfe32fa1Soh_ci */
46dfe32fa1Soh_ci
47dfe32fa1Soh_ci#ifdef __cplusplus
48dfe32fa1Soh_ciextern "C" {
49dfe32fa1Soh_ci#endif
50dfe32fa1Soh_ci/**
51dfe32fa1Soh_ci * @brief Adds an asset.
52dfe32fa1Soh_ci *
53dfe32fa1Soh_ci * @param attributes Pointer to the attributes of the asset to add.
54dfe32fa1Soh_ci * @param attributes Number of the attributes of the asset to add.
55dfe32fa1Soh_ci * @return {@link ASSET_SUCCESS} 0 - The operation is successful.
56dfe32fa1Soh_ci *     {@link ASSET_PERMISSION_DENIED} 201 - The caller doesn't have the permission.
57dfe32fa1Soh_ci *     {@link ASSET_INVALID_ARGUMENT} 401 - Parameter error. Possible causes:
58dfe32fa1Soh_ci *         1. Mandatory parameters are left unspecified.
59dfe32fa1Soh_ci *         2. Incorrect parameter types.
60dfe32fa1Soh_ci *         3. Parameter verification failed.
61dfe32fa1Soh_ci *     {@link ASSET_SERVICE_UNAVAILABLE} 24000001 - The ASSET service is unavailable.
62dfe32fa1Soh_ci *     {@link ASSET_DUPLICATED} 24000003 - The asset already exists.
63dfe32fa1Soh_ci *     {@link ASSET_STATUS_MISMATCH} 24000005 - The screen lock status does not match.
64dfe32fa1Soh_ci *     {@link ASSET_OUT_OF_MEMORY} 24000006 - Insufficient memory.
65dfe32fa1Soh_ci *     {@link ASSET_DATA_CORRUPTED} 24000007 - The asset is corrupted.
66dfe32fa1Soh_ci *     {@link ASSET_DATABASE_ERROR} 24000008 - The database operation failed.
67dfe32fa1Soh_ci *     {@link ASSET_CRYPTO_ERROR} 24000009 - The cryptography operation failed.
68dfe32fa1Soh_ci *     {@link ASSET_IPC_ERROR} 24000010 - IPC failed.
69dfe32fa1Soh_ci *     {@link ASSET_BMS_ERROR} 24000011 - Calling the Bundle Manager service failed.
70dfe32fa1Soh_ci *     {@link ASSET_ACCOUNT_ERROR} 24000012 - Calling the OS Account service failed.
71dfe32fa1Soh_ci *     {@link ASSET_ACCESS_TOKEN_ERROR} 24000013 - Calling the Access Token service failed.
72dfe32fa1Soh_ci *     {@link ASSET_FILE_OPERATION_ERROR} 24000014 - The file operation failed.
73dfe32fa1Soh_ci *     {@link ASSET_GET_SYSTEM_TIME_ERROR} 24000015 - Getting the system time failed.
74dfe32fa1Soh_ci * @since 11
75dfe32fa1Soh_ci */
76dfe32fa1Soh_ciint32_t OH_Asset_Add(const Asset_Attr *attributes, uint32_t attrCnt);
77dfe32fa1Soh_ci
78dfe32fa1Soh_ci/**
79dfe32fa1Soh_ci * @brief Removes one or more assets.
80dfe32fa1Soh_ci *
81dfe32fa1Soh_ci * @param query Pointer to the conditions for removing the assets.
82dfe32fa1Soh_ci * @param queryCnt Number of conditions for removing the assets.
83dfe32fa1Soh_ci * @return {@link ASSET_SUCCESS} 0 - The operation is successful.
84dfe32fa1Soh_ci *     {@link ASSET_INVALID_ARGUMENT} 401 - Parameter error. Possible causes:
85dfe32fa1Soh_ci *         1. Incorrect parameter types.
86dfe32fa1Soh_ci *         2. Parameter verification failed.
87dfe32fa1Soh_ci *     {@link ASSET_SERVICE_UNAVAILABLE} 24000001 - The ASSET service is unavailable.
88dfe32fa1Soh_ci *     {@link ASSET_NOT_FOUND} 24000002 - The asset is not found.
89dfe32fa1Soh_ci *     {@link ASSET_OUT_OF_MEMORY} 24000006 - Insufficient memory.
90dfe32fa1Soh_ci *     {@link ASSET_DATA_CORRUPTED} 24000007 - The asset is corrupted.
91dfe32fa1Soh_ci *     {@link ASSET_DATABASE_ERROR} 24000008 - The database operation failed.
92dfe32fa1Soh_ci *     {@link ASSET_IPC_ERROR} 24000010 - IPC failed.
93dfe32fa1Soh_ci *     {@link ASSET_BMS_ERROR} 24000011 - Calling the Bundle Manager service failed.
94dfe32fa1Soh_ci *     {@link ASSET_ACCOUNT_ERROR} 24000012 - Calling the OS Account service failed.
95dfe32fa1Soh_ci *     {@link ASSET_ACCESS_TOKEN_ERROR} 24000013 - Calling the Access Token service failed.
96dfe32fa1Soh_ci *     {@link ASSET_GET_SYSTEM_TIME_ERROR} 24000015 - Getting the system time failed.
97dfe32fa1Soh_ci * @since 11
98dfe32fa1Soh_ci */
99dfe32fa1Soh_ciint32_t OH_Asset_Remove(const Asset_Attr *query, uint32_t queryCnt);
100dfe32fa1Soh_ci
101dfe32fa1Soh_ci/**
102dfe32fa1Soh_ci * @brief Updates an asset.
103dfe32fa1Soh_ci *
104dfe32fa1Soh_ci * @param query Pointer to the conditions for updating the asset.
105dfe32fa1Soh_ci * @param queryCnt Number of conditions for updating the asset.
106dfe32fa1Soh_ci * @param attributes Pointer to the attributes of the asset to update.
107dfe32fa1Soh_ci * @param attributes Number of the attributes of the asset to update.
108dfe32fa1Soh_ci * @return {@link ASSET_SUCCESS} 0 - The operation is successful.
109dfe32fa1Soh_ci *     {@link ASSET_INVALID_ARGUMENT} 401 - Parameter error. Possible causes:
110dfe32fa1Soh_ci *         1. Mandatory parameters are left unspecified.
111dfe32fa1Soh_ci *         2. Incorrect parameter types.
112dfe32fa1Soh_ci *         3. Parameter verification failed.
113dfe32fa1Soh_ci *     {@link ASSET_SERVICE_UNAVAILABLE} 24000001 - The ASSET service is unavailable.
114dfe32fa1Soh_ci *     {@link ASSET_NOT_FOUND} 24000002 - The asset is not found.
115dfe32fa1Soh_ci *     {@link ASSET_STATUS_MISMATCH} 24000005 - The screen lock status does not match.
116dfe32fa1Soh_ci *     {@link ASSET_OUT_OF_MEMORY} 24000006 - Insufficient memory.
117dfe32fa1Soh_ci *     {@link ASSET_DATA_CORRUPTED} 24000007 - The asset is corrupted.
118dfe32fa1Soh_ci *     {@link ASSET_DATABASE_ERROR} 24000008 - The database operation failed.
119dfe32fa1Soh_ci *     {@link ASSET_CRYPTO_ERROR} 24000009 - The cryptography operation failed.
120dfe32fa1Soh_ci *     {@link ASSET_IPC_ERROR} 24000010 - IPC failed.
121dfe32fa1Soh_ci *     {@link ASSET_BMS_ERROR} 24000011 - Calling the Bundle Manager service failed.
122dfe32fa1Soh_ci *     {@link ASSET_ACCOUNT_ERROR} 24000012 - Calling the OS Account service failed.
123dfe32fa1Soh_ci *     {@link ASSET_ACCESS_TOKEN_ERROR} 24000013 - Calling the Access Token service failed.
124dfe32fa1Soh_ci *     {@link ASSET_GET_SYSTEM_TIME_ERROR} 24000015 - Getting the system time failed.
125dfe32fa1Soh_ci * @since 11
126dfe32fa1Soh_ci */
127dfe32fa1Soh_ciint32_t OH_Asset_Update(const Asset_Attr *query, uint32_t queryCnt,
128dfe32fa1Soh_ci    const Asset_Attr *attributesToUpdate, uint32_t updateCnt);
129dfe32fa1Soh_ci
130dfe32fa1Soh_ci/**
131dfe32fa1Soh_ci * @brief Preprocesses data before querying the asset that can be accessed only after a successful user authentication.
132dfe32fa1Soh_ci *
133dfe32fa1Soh_ci * @param query Pointer to the search criteria of the asset.
134dfe32fa1Soh_ci * @param queryCnt Number of the search criteria.
135dfe32fa1Soh_ci * @param challenge Pointer to the challenge value to be used when <b>OH_Asset_Query</b> is called.
136dfe32fa1Soh_ci * @return {@link ASSET_SUCCESS} 0 - The operation is successful.
137dfe32fa1Soh_ci *     {@link ASSET_INVALID_ARGUMENT} 401 - Parameter error. Possible causes:
138dfe32fa1Soh_ci *         1. Incorrect parameter types.
139dfe32fa1Soh_ci *         2. Parameter verification failed.
140dfe32fa1Soh_ci *     {@link ASSET_SERVICE_UNAVAILABLE} 24000001 - The ASSET service is unavailable.
141dfe32fa1Soh_ci *     {@link ASSET_NOT_FOUND} 24000002 - The asset is not found.
142dfe32fa1Soh_ci *     {@link ASSET_STATUS_MISMATCH} 24000005 - The screen lock status does not match.
143dfe32fa1Soh_ci *     {@link ASSET_OUT_OF_MEMORY} 24000006 - Insufficient memory.
144dfe32fa1Soh_ci *     {@link ASSET_DATA_CORRUPTED} 24000007 - The asset is corrupted.
145dfe32fa1Soh_ci *     {@link ASSET_DATABASE_ERROR} 24000008 - The database operation failed.
146dfe32fa1Soh_ci *     {@link ASSET_CRYPTO_ERROR} 24000009 - The cryptography operation failed.
147dfe32fa1Soh_ci *     {@link ASSET_IPC_ERROR} 24000010 - IPC failed.
148dfe32fa1Soh_ci *     {@link ASSET_BMS_ERROR} 24000011 - Calling the Bundle Manager service failed.
149dfe32fa1Soh_ci *     {@link ASSET_ACCOUNT_ERROR} 24000012 - Calling the OS Account service failed.
150dfe32fa1Soh_ci *     {@link ASSET_ACCESS_TOKEN_ERROR} 24000013 - Calling the Access Token service failed.
151dfe32fa1Soh_ci *     {@link ASSET_LIMIT_EXCEEDED} 24000016 - The cache exceeds the limit.
152dfe32fa1Soh_ci *     {@link ASSET_UNSUPPORTED} 24000017 - The capability is not supported.
153dfe32fa1Soh_ci * @since 11
154dfe32fa1Soh_ci */
155dfe32fa1Soh_ciint32_t OH_Asset_PreQuery(const Asset_Attr *query, uint32_t queryCnt, Asset_Blob *challenge);
156dfe32fa1Soh_ci
157dfe32fa1Soh_ci/**
158dfe32fa1Soh_ci * @brief Queries assets.
159dfe32fa1Soh_ci *
160dfe32fa1Soh_ci * @param query Pointer to the search criteria.
161dfe32fa1Soh_ci * @param queryCnt Number of the search criteria.
162dfe32fa1Soh_ci * @param resultSet Pointer to the query result obtained.
163dfe32fa1Soh_ci * @return {@link ASSET_SUCCESS} 0 - The operation is successful.
164dfe32fa1Soh_ci *     {@link ASSET_INVALID_ARGUMENT} 401 - Parameter error. Possible causes:
165dfe32fa1Soh_ci *         1. Incorrect parameter types.
166dfe32fa1Soh_ci *         2. Parameter verification failed.
167dfe32fa1Soh_ci *     {@link ASSET_SERVICE_UNAVAILABLE} 24000001 - The ASSET service is unavailable.
168dfe32fa1Soh_ci *     {@link ASSET_NOT_FOUND} 24000002 - The asset is not found.
169dfe32fa1Soh_ci *     {@link ASSET_ACCESS_DENIED} 24000004 - Access to the asset is denied.
170dfe32fa1Soh_ci *     {@link ASSET_STATUS_MISMATCH} 24000005 - The screen lock status does not match.
171dfe32fa1Soh_ci *     {@link ASSET_OUT_OF_MEMORY} 24000006 - Insufficient memory.
172dfe32fa1Soh_ci *     {@link ASSET_DATA_CORRUPTED} 24000007 - The asset is corrupted.
173dfe32fa1Soh_ci *     {@link ASSET_DATABASE_ERROR} 24000008 - The database operation failed.
174dfe32fa1Soh_ci *     {@link ASSET_CRYPTO_ERROR} 24000009 - The cryptography operation failed.
175dfe32fa1Soh_ci *     {@link ASSET_IPC_ERROR} 24000010 - IPC failed.
176dfe32fa1Soh_ci *     {@link ASSET_BMS_ERROR} 24000011 - Calling the Bundle Manager service failed.
177dfe32fa1Soh_ci *     {@link ASSET_ACCOUNT_ERROR} 24000012 - Calling the OS Account service failed.
178dfe32fa1Soh_ci *     {@link ASSET_ACCESS_TOKEN_ERROR} 24000013 - Calling the Access Token service failed.
179dfe32fa1Soh_ci *     {@link ASSET_UNSUPPORTED} 24000017 - The capability is not supported.
180dfe32fa1Soh_ci * @since 11
181dfe32fa1Soh_ci */
182dfe32fa1Soh_ciint32_t OH_Asset_Query(const Asset_Attr *query, uint32_t queryCnt, Asset_ResultSet *resultSet);
183dfe32fa1Soh_ci
184dfe32fa1Soh_ci/**
185dfe32fa1Soh_ci * @brief Processes data after the query of the asset that requires user authentication.
186dfe32fa1Soh_ci *
187dfe32fa1Soh_ci * @param handle Pointer to the handle of the data to process, which includes the challenge value returned by
188dfe32fa1Soh_ci *     <b>OH_Asset_PreQuery</b>.
189dfe32fa1Soh_ci * @param handleCnt Number of the elements in the handle attribute set.
190dfe32fa1Soh_ci * @return {@link ASSET_SUCCESS} 0 - The operation is successful.
191dfe32fa1Soh_ci *     {@link ASSET_INVALID_ARGUMENT} 401 - Parameter error. Possible causes:
192dfe32fa1Soh_ci *         1. Mandatory parameters are left unspecified.
193dfe32fa1Soh_ci *         2. Incorrect parameter types.
194dfe32fa1Soh_ci *         3. Parameter verification failed.
195dfe32fa1Soh_ci *     {@link ASSET_SERVICE_UNAVAILABLE} 24000001 - The ASSET service is unavailable.
196dfe32fa1Soh_ci *     {@link ASSET_OUT_OF_MEMORY} 24000006 - Insufficient memory.
197dfe32fa1Soh_ci *     {@link ASSET_IPC_ERROR} 24000010 - IPC failed.
198dfe32fa1Soh_ci *     {@link ASSET_BMS_ERROR} 24000011 - Calling the Bundle Manager service failed.
199dfe32fa1Soh_ci *     {@link ASSET_ACCOUNT_ERROR} 24000012 - Calling the OS Account service failed.
200dfe32fa1Soh_ci *     {@link ASSET_ACCESS_TOKEN_ERROR} 24000013 - Calling the Access Token service failed.
201dfe32fa1Soh_ci * @since 11
202dfe32fa1Soh_ci */
203dfe32fa1Soh_ciint32_t OH_Asset_PostQuery(const Asset_Attr *handle, uint32_t handleCnt);
204dfe32fa1Soh_ci
205dfe32fa1Soh_ci/**
206dfe32fa1Soh_ci * @brief Parses the query result to obtain the specified attribute value.
207dfe32fa1Soh_ci *
208dfe32fa1Soh_ci * @param result Pointer to the query result to parse, which is obtained by <b>OH_Asset_Query</b>.
209dfe32fa1Soh_ci * @param tag Tag of the attribute to obtain.
210dfe32fa1Soh_ci * @return Returns <b>Asset_Attr</b> obtained if the operation is successful; returns <b>NULL</b> otherwise.
211dfe32fa1Soh_ci *     The attribute does not need to be released by the service.
212dfe32fa1Soh_ci * @since 11
213dfe32fa1Soh_ci */
214dfe32fa1Soh_ciAsset_Attr *OH_Asset_ParseAttr(const Asset_Result *result, Asset_Tag tag);
215dfe32fa1Soh_ci
216dfe32fa1Soh_ci/**
217dfe32fa1Soh_ci * @brief Releases the memory occupied by the challenge value.
218dfe32fa1Soh_ci *
219dfe32fa1Soh_ci * @param blob Pointer to the challenge value (obtained by <b>OH_Asset_PreQuery</b>) to release.
220dfe32fa1Soh_ci * @since 11
221dfe32fa1Soh_ci */
222dfe32fa1Soh_civoid OH_Asset_FreeBlob(Asset_Blob *blob);
223dfe32fa1Soh_ci
224dfe32fa1Soh_ci/**
225dfe32fa1Soh_ci * @brief Releases the memory occupied by the query result.
226dfe32fa1Soh_ci *
227dfe32fa1Soh_ci * @param resultSet Pointer to the query result (obtained by <b>OH_Asset_Query</b>) to release.
228dfe32fa1Soh_ci * @since 11
229dfe32fa1Soh_ci */
230dfe32fa1Soh_civoid OH_Asset_FreeResultSet(Asset_ResultSet *resultSet);
231dfe32fa1Soh_ci
232dfe32fa1Soh_ci#ifdef __cplusplus
233dfe32fa1Soh_ci}
234dfe32fa1Soh_ci#endif
235dfe32fa1Soh_ci
236dfe32fa1Soh_ci/** @} */
237dfe32fa1Soh_ci#endif // ASSET_API_H
238