1# AssetApi
2
3
4## Overview
5
6Provides functions for adding, removing, updating, and querying sensitive data less than 1024 bytes in size,
7including passwords, app tokens, and other critical data (such as bank card numbers).
8
9**System capability**: SystemCapability.Security.Asset
10
11**Since**: 11
12
13
14## Summary
15
16
17### Files
18
19| Name| Description|
20| -------- | -------- |
21| [asset_api.h](asset__api_8h.md) | Defines the functions for accessing assets. |
22
23
24### Functions
25
26| Name| Description|
27| -------- | -------- |
28| int32_t [OH_Asset_Add](#oh_asset_add) (const [Asset_Attr](_asset___attr.md) \*attributes, uint32_t attrCnt) | Adds an asset. |
29| int32_t [OH_Asset_Remove](#oh_asset_remove) (const [Asset_Attr](_asset___attr.md) \*query, uint32_t queryCnt) | Removes one or more assets. |
30| int32_t [OH_Asset_Update](#oh_asset_update) (const [Asset_Attr](_asset___attr.md) \*query, uint32_t queryCnt, const [Asset_Attr](_asset___attr.md) \*attributesToUpdate, uint32_t updateCnt) | Updates an asset. |
31| int32_t [OH_Asset_PreQuery](#oh_asset_prequery) (const [Asset_Attr](_asset___attr.md) \*query, uint32_t queryCnt, [Asset_Blob](_asset___blob.md) \*challenge) | Performs preprocessing for the asset query. This function is used when user authentication is required for the access to the asset. |
32| int32_t [OH_Asset_Query](#oh_asset_query) (const [Asset_Attr](_asset___attr.md) \*query, uint32_t queryCnt, [Asset_ResultSet](_asset___result_set.md) \*resultSet) | Queries one or more assets. |
33| int32_t [OH_Asset_PostQuery](#oh_asset_postquery) (const [Asset_Attr](_asset___attr.md) \*handle, uint32_t handleCnt) | Performs postprocessing for the asset query. This function is used when user authentication is required for the access to the asset. |
34| [Asset_Attr](_asset___attr.md) \* [OH_Asset_ParseAttr](#oh_asset_parseattr) (const [Asset_Result](_asset___result.md) \*result, [Asset_Tag](_asset_type.md#asset_tag) tag) | Parses the query result and obtains the specified attribute. |
35| void [OH_Asset_FreeBlob](#oh_asset_freeblob) ([Asset_Blob](_asset___blob.md) \*blob) | Releases the memory occupied by the challenge value. |
36| void [OH_Asset_FreeResultSet](#oh_asset_freeresultset) ([Asset_ResultSet](_asset___result_set.md) \*resultSet) | Releases the memory occupied by the query result. |
37
38
39## Function Description
40
41
42### OH_Asset_Add()
43
44```
45int32_t OH_Asset_Add (const Asset_Attr * attributes, uint32_t attrCnt )
46```
47**Description**
48Adds an asset.
49
50**Since**: 11
51
52**Parameters**
53
54| Name| Description|
55| -------- | -------- |
56| attributes | Attributes of the asset to add |
57| attrCnt | Number of attributes of the asset to add. |
58
59**Returns**
60
61Returns [ASSET_SUCCESS](_asset_type.md#asset_resultcode) if the operation is successful; returns an error code otherwise.
62
63
64### OH_Asset_FreeBlob()
65
66```
67void OH_Asset_FreeBlob (Asset_Blob * blob)
68```
69**Description**
70Releases the memory occupied by the challenge value.
71
72**Since**: 11
73
74**Parameters**
75
76| Name| Description|
77| -------- | -------- |
78| blob | Challenge value returned by **OH_Asset_PreQuery**. |
79
80
81### OH_Asset_FreeResultSet()
82
83```
84void OH_Asset_FreeResultSet (Asset_ResultSet * resultSet)
85```
86**Description**
87Releases the memory occupied by the query result.
88
89**Since**: 11
90
91**Parameters**
92
93| Name| Description|
94| -------- | -------- |
95| resultSet | Query result returned by **OH_Asset_Query**. |
96
97
98### OH_Asset_ParseAttr()
99
100```
101Asset_Attr* OH_Asset_ParseAttr (const Asset_Result * result, Asset_Tag tag )
102```
103**Description**
104Parses the query result and obtains the specified attribute.
105
106**Since**: 11
107
108**Parameters**
109
110| Name| Description|
111| -------- | -------- |
112| result | Query result returned by OH_Asset_Query. |
113| tag | Key of the attribute to obtain. |
114
115**Returns**
116
117Returns <b>Asset_Attr</b> obtained if the operation is successful; returns <b>NULL</b> otherwise. The attribute does not need to be released by the service.
118
119
120### OH_Asset_PostQuery()
121
122```
123int32_t OH_Asset_PostQuery (const Asset_Attr * handle, uint32_t handleCnt )
124```
125**Description**
126Performs postprocessing for the asset query. This API is used when user authentication is required for the access to the asset.
127
128**Since**: 11
129
130**Parameters**
131
132| Name| Description|
133| -------- | -------- |
134| handle | Handle of the query operation, including the challenge value returned by **OH_Asset_PreQuery**. |
135| handleCnt | Number of elements in the handle attribute set. |
136
137**Returns**
138
139Returns [ASSET_SUCCESS](_asset_type.md#asset_resultcode) if the operation is successful; returns an error code otherwise.
140
141
142### OH_Asset_PreQuery()
143
144```
145int32_t OH_Asset_PreQuery (const Asset_Attr * query, uint32_t queryCnt, Asset_Blob * challenge )
146```
147**Description**
148Performs preprocessing for the asset query. This API is used when user authentication is required for the access to the asset.
149
150**Since**: 11
151
152**Parameters**
153
154| Name| Description|
155| -------- | -------- |
156| query | Attributes of the asset to query. |
157| queryCnt | Number of attributes. |
158| challenge | Challenge value, which is used when **OH_Asset_Query** is called. |
159
160**Returns**
161
162Returns [ASSET_SUCCESS](_asset_type.md#asset_resultcode) if the operation is successful; returns an error code otherwise.
163
164
165### OH_Asset_Query()
166
167```
168int32_t OH_Asset_Query (const Asset_Attr * query, uint32_t queryCnt, Asset_ResultSet * resultSet )
169```
170**Description**
171Queries one or more assets.
172
173**Since**: 11
174
175**Parameters**
176
177| Name| Description|
178| -------- | -------- |
179| query | Attributes of the asset to query. |
180| queryCnt | Number of attributes. |
181| resultSet | Array of query results. |
182
183**Returns**
184
185Returns [ASSET_SUCCESS](_asset_type.md#asset_resultcode) if the operation is successful; returns an error code otherwise.
186
187### OH_Asset_Remove()
188
189```
190int32_t OH_Asset_Remove (const Asset_Attr * query, uint32_t queryCnt )
191```
192**Description**
193Removes one or more assets.
194
195**Since**: 11
196
197**Parameters**
198
199| Name| Description|
200| -------- | -------- |
201| query | Attributes of the asset to remove. |
202| queryCnt | Number of Attributes. |
203
204**Returns**
205
206Returns [ASSET_SUCCESS](_asset_type.md#asset_resultcode) if the operation is successful; returns an error code otherwise.
207
208
209### OH_Asset_Update()
210
211```
212int32_t OH_Asset_Update (const Asset_Attr * query, uint32_t queryCnt, const Asset_Attr * attributesToUpdate, uint32_t updateCnt )
213```
214**Description**
215Updates an asset.
216
217**Since**: 11
218
219**Parameters**
220
221| Name| Description|
222| -------- | -------- |
223| query | Attributes of the asset to update. |
224| queryCnt | Number of attributes to update. |
225| attributesToUpdate | New attributes of the asset. |
226| updateCnt | Number of new attributes. |
227
228**Returns**
229
230Returns [ASSET_SUCCESS](_asset_type.md#asset_resultcode) if the operation is successful; returns an error code otherwise.
231