1# Update an Asset (C/C++) 2 3## Available APIs 4 5You can use [OH_Asset_Update](../../reference/apis-asset-store-kit/capi-asset-api-h.md#oh_asset_update) to update an asset. 6 7The following table describes the attributes for updating an asset. 8 9>**NOTE** 10> 11>In the following table, the attributes starting with **DATA_LABEL** are custom asset attributes reserved for services. These attributes are not encrypted. Therefore, do not put personal data in these attributes. 12 13- Attributes in **query**: 14 15 | Attribute Name (Asset_Tag) | Attribute Content (Asset_Value) | Mandatory| Description | 16 | ------------------------------- | ------------------------------------------------------------ | -------- | ------------------------------------------------ | 17 | ASSET_TAG_ALIAS | Type: uint8[]<br>Length: 1-256 bytes | Yes | Asset alias, which uniquely identifies an asset. | 18 | ASSET_TAG_ACCESSIBILITY | Type: uint32_t<br>Value range: see [Asset_Accessibility](../../reference/apis-asset-store-kit/capi-asset-type-h.md#asset_accessibility).| No | Access control based on the lock screen status. | 19 | ASSET_TAG_REQUIRE_PASSWORD_SET | Type: bool | No | Whether the asset is accessible only when a lock screen password is set. The value **true** means the asset is accessible only when a lock screen password is set. The value **false** means that the asset can be accessed regardless of whether a lock screen password is set. | 20 | ASSET_TAG_AUTH_TYPE | Type: uint32_t<br>Value range: see [Asset_AuthType](../../reference/apis-asset-store-kit/capi-asset-type-h.md#asset_authtype).| No | Type of user authentication required for accessing the asset. | 21 | ASSET_TAG_SYNC_TYPE | Type: uint32_t<br>Value range: see [Asset_SyncType](../../reference/apis-asset-store-kit/capi-asset-type-h.md#asset_synctype).| No | Type of sync supported by the asset. | 22 | ASSET_TAG_IS_PERSISTENT | Type: bool | No | Whether to retain the asset when the application is uninstalled. The value **true** means to retain the asset even after the application is uninstalled. The value **false** means the opposite. | 23 | ASSET_TAG_DATA_LABEL_CRITICAL_1 | Type: uint8[]<br>Length: 1-2048 bytes | No | Asset attribute information customized by the service with integrity protection.<br>**NOTE**: The data length is 1 to 512 bytes before API version 12.| 24 | ASSET_TAG_DATA_LABEL_CRITICAL_2 | Type: uint8[]<br>Length: 1-2048 bytes | No | Asset attribute information customized by the service with integrity protection.<br>**NOTE**: The data length is 1 to 512 bytes before API version 12.| 25 | ASSET_TAG_DATA_LABEL_CRITICAL_3 | Type: uint8[]<br>Length: 1-2048 bytes | No | Asset attribute information customized by the service with integrity protection.<br>**NOTE**: The data length is 1 to 512 bytes before API version 12.| 26 | ASSET_TAG_DATA_LABEL_CRITICAL_4 | Type: uint8[]<br>Length: 1-2048 bytes | No | Asset attribute information customized by the service with integrity protection.<br>**NOTE**: The data length is 1 to 512 bytes before API version 12.| 27 | ASSET_TAG_DATA_LABEL_NORMAL_1 | Type: uint8[]<br>Length: 1-2048 bytes | No | Asset attribute information customized by the service without integrity protection.<br>**NOTE**: The data length is 1 to 512 bytes before API version 12.| 28 | ASSET_TAG_DATA_LABEL_NORMAL_2 | Type: uint8[]<br>Length: 1-2048 bytes | No | Asset attribute information customized by the service without integrity protection.<br>**NOTE**: The data length is 1 to 512 bytes before API version 12.| 29 | ASSET_TAG_DATA_LABEL_NORMAL_3 | Type: uint8[]<br>Length: 1-2048 bytes | No | Asset attribute information customized by the service without integrity protection.<br>**NOTE**: The data length is 1 to 512 bytes before API version 12.| 30 | ASSET_TAG_DATA_LABEL_NORMAL_4 | Type: uint8[]<br>Length: 1-2048 bytes | No | Asset attribute information customized by the service without integrity protection.<br>**NOTE**: The data length is 1 to 512 bytes before API version 12.| 31 | ASSET_TAG_DATA_LABEL_NORMAL_LOCAL_1<sup>12+</sup> | Type: uint8[]<br>Length: 1-2048 bytes| No| Local attribute information about the asset. The value is assigned by the service without integrity protection and will not be synced.| 32 | ASSET_TAG_DATA_LABEL_NORMAL_LOCAL_2<sup>12+</sup> | Type: uint8[]<br>Length: 1-2048 bytes| No| Local attribute information about the asset. The value is assigned by the service without integrity protection and will not be synced.| 33 | ASSET_TAG_DATA_LABEL_NORMAL_LOCAL_3<sup>12+</sup> | Type: uint8[]<br>Length: 1-2048 bytes| No| Local attribute information about the asset. The value is assigned by the service without integrity protection and will not be synced.| 34 | ASSET_TAG_DATA_LABEL_NORMAL_LOCAL_4<sup>12+</sup> | Type: uint8[]<br>Length: 1-2048 bytes| No| Local attribute information about the asset. The value is assigned by the service without integrity protection and will not be synced.| 35 | ASSET_TAG_REQUIRE_ATTR_ENCRYPTED<sup>14+</sup> | Type: bool| No| Whether to update the encrypted data of service customized supplementary information. The value **true** means to update the encrypted data of service customized supplementary information; the value **false** means to update the non-encrypted data of service customized supplementary information. Default value: **false**.| 36 | ASSET_TAG_GROUP_ID<sup>18+</sup> | Type: Uint8[]<br>Length: 7-127 bytes| No| Group to which the asset to be updated belongs. By default, this parameter is not specified.| 37 38- Attributes in **attributesToUpdate**: 39 40 | Attribute Name (Asset_Tag)| Attribute Content (Asset_Value) | Mandatory| Description | 41 | ------------------- | ------------------------------- | -------- | ------------------------------------------------ | 42 | ASSET_TAG_SECRET | Type: uint8[]<br>Length: 1-1024 bytes| No | New asset in plaintext. | 43 | ASSET_TAG_DATA_LABEL_NORMAL_1 | Type: uint8[]<br>Length: 1-2048 bytes| No | Asset attribute information customized by the service without integrity protection.<br>**NOTE**: The data length is 1 to 512 bytes before API version 12.| 44 | ASSET_TAG_DATA_LABEL_NORMAL_2 | Type: uint8[]<br>Length: 1-2048 bytes| No | Asset attribute information customized by the service without integrity protection.<br>**NOTE**: The data length is 1 to 512 bytes before API version 12.| 45 | ASSET_TAG_DATA_LABEL_NORMAL_3 | Type: uint8[]<br>Length: 1-2048 bytes| No | Asset attribute information customized by the service without integrity protection.<br>**NOTE**: The data length is 1 to 512 bytes before API version 12.| 46 | ASSET_TAG_DATA_LABEL_NORMAL_4 | Type: uint8[]<br>Length: 1-2048 bytes| No | Asset attribute information customized by the service without integrity protection.<br>**NOTE**: The data length is 1 to 512 bytes before API version 12.| 47 | ASSET_TAG_DATA_LABEL_NORMAL_LOCAL_1<sup>12+</sup> | Type: uint8[]<br>Length: 1-2048 bytes| No| Local attribute information about the asset. The value is assigned by the service without integrity protection and will not be synced.| 48 | ASSET_TAG_DATA_LABEL_NORMAL_LOCAL_2<sup>12+</sup> | Type: uint8[]<br>Length: 1-2048 bytes| No| Local attribute information about the asset. The value is assigned by the service without integrity protection and will not be synced.| 49 | ASSET_TAG_DATA_LABEL_NORMAL_LOCAL_3<sup>12+</sup> | Type: uint8[]<br>Length: 1-2048 bytes| No| Local attribute information about the asset. The value is assigned by the service without integrity protection and will not be synced.| 50 | ASSET_TAG_DATA_LABEL_NORMAL_LOCAL_4<sup>12+</sup> | Type: uint8[]<br>Length: 1-2048 bytes| No| Local attribute information about the asset. The value is assigned by the service without integrity protection and will not be synced.| 51 52## Example 53 54Update asset **demo_alias** as follows: change the asset plaintext to **demo_pwd_new** and additional attribute to **demo_label_new**. 55 56For details about how to update an asset in a group, see [Updating an asset in a Group](asset-native-group-access-control.md#updating-an-asset-in-a-group). 57 581. Link the dynamic libraries in the CMake script. 59 ```txt 60 target_link_libraries(entry PUBLIC libasset_ndk.z.so) 61 ``` 62 632. Update an asset. 64 ```c 65 #include <string.h> 66 67 #include "asset/asset_api.h" 68 69 void UpdateAsset() { 70 static const char *ALIAS = "demo_alias"; 71 static const char *SECRET = "demo_pwd_new"; 72 static const char *LABEL = "demo_label_new"; 73 74 Asset_Blob alias = { (uint32_t)(strlen(ALIAS)), (uint8_t *)ALIAS }; 75 Asset_Blob new_secret = { (uint32_t)(strlen(SECRET)), (uint8_t *)SECRET }; 76 Asset_Blob new_label = { (uint32_t)(strlen(LABEL)), (uint8_t *)LABEL }; 77 Asset_Attr query[] = { { .tag = ASSET_TAG_ALIAS, .value.blob = alias } }; 78 Asset_Attr attributesToUpdate[] = { 79 { .tag = ASSET_TAG_SECRET, .value.blob = new_secret }, 80 { .tag = ASSET_TAG_DATA_LABEL_NORMAL_1, .value.blob = new_label }, 81 }; 82 83 int32_t ret = OH_Asset_Update(query, sizeof(query) / sizeof(query[0]), attributesToUpdate, 84 sizeof(attributesToUpdate) / sizeof(attributesToUpdate[0])); 85 if (ret == ASSET_SUCCESS) { 86 // Asset updated successfully. 87 } else { 88 // Failed to update Asset. 89 } 90 } 91 ``` 92