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 */ 118 ASSET_TAG_IS_PERSISTENT = ASSET_TYPE_BOOL | 0x11, 119 /** 120 * An immutable custom field, in the form of bytes. 121 */ 122 ASSET_TAG_DATA_LABEL_CRITICAL_1 = ASSET_TYPE_BYTES | 0x20, 123 /** 124 * An immutable custom field, in the form of bytes. 125 */ 126 ASSET_TAG_DATA_LABEL_CRITICAL_2 = ASSET_TYPE_BYTES | 0x21, 127 /** 128 * An immutable custom field, in the form of bytes. 129 */ 130 ASSET_TAG_DATA_LABEL_CRITICAL_3 = ASSET_TYPE_BYTES | 0x22, 131 /** 132 * An immutable custom field, in the form of bytes. 133 */ 134 ASSET_TAG_DATA_LABEL_CRITICAL_4 = ASSET_TYPE_BYTES | 0x23, 135 /** 136 * A mutable custom field, in the form of bytes. 137 */ 138 ASSET_TAG_DATA_LABEL_NORMAL_1 = ASSET_TYPE_BYTES | 0x30, 139 /** 140 * A mutable custom field, in the form of bytes. 141 */ 142 ASSET_TAG_DATA_LABEL_NORMAL_2 = ASSET_TYPE_BYTES | 0x31, 143 /** 144 * A mutable custom field, in the form of bytes. 145 */ 146 ASSET_TAG_DATA_LABEL_NORMAL_3 = ASSET_TYPE_BYTES | 0x32, 147 /** 148 * A mutable custom field, in the form of bytes. 149 */ 150 ASSET_TAG_DATA_LABEL_NORMAL_4 = ASSET_TYPE_BYTES | 0x33, 151 /** 152 * A mutable custom field, in the form of bytes. The information of a local tag will not be synchronized. 153 * 154 * @since 12 155 */ 156 ASSET_TAG_DATA_LABEL_NORMAL_LOCAL_1 = ASSET_TYPE_BYTES | 0x34, 157 /** 158 * A mutable custom field, in the form of bytes. The information of a local tag will not be synchronized. 159 * 160 * @since 12 161 */ 162 ASSET_TAG_DATA_LABEL_NORMAL_LOCAL_2 = ASSET_TYPE_BYTES | 0x35, 163 /** 164 * A mutable custom field, in the form of bytes. The information of a local tag will not be synchronized. 165 * 166 * @since 12 167 */ 168 ASSET_TAG_DATA_LABEL_NORMAL_LOCAL_3 = ASSET_TYPE_BYTES | 0x36, 169 /** 170 * A mutable custom field, in the form of bytes. The information of a local tag will not be synchronized. 171 * 172 * @since 12 173 */ 174 ASSET_TAG_DATA_LABEL_NORMAL_LOCAL_4 = ASSET_TYPE_BYTES | 0x37, 175 /** 176 * Return type of the queried asset. The value is of the uint32 type. 177 */ 178 ASSET_TAG_RETURN_TYPE = ASSET_TYPE_NUMBER | 0x40, 179 /** 180 * Maximum number of assets that can be returned at a time if multiple asset records match the specified conditions. 181 * The value is of the uint32 type. 182 */ 183 ASSET_TAG_RETURN_LIMIT = ASSET_TYPE_NUMBER | 0x41, 184 /** 185 * Offset that indicates the start asset when multiple asset records are returned. The value is of the uint32 type. 186 */ 187 ASSET_TAG_RETURN_OFFSET = ASSET_TYPE_NUMBER | 0x42, 188 /** 189 * Sorting order of the assets in the query result. The value is of the uint32 type. 190 */ 191 ASSET_TAG_RETURN_ORDERED_BY = ASSET_TYPE_NUMBER | 0x43, 192 /** 193 * Policy used to resolve the conflict occurred when an asset is added. The value is of the uint32 type. 194 */ 195 ASSET_TAG_CONFLICT_RESOLUTION = ASSET_TYPE_NUMBER | 0x44, 196 /** 197 * A tag whose value is a byte array indicating the update time of an Asset. 198 * 199 * @since 12 200 */ 201 ASSET_TAG_UPDATE_TIME = ASSET_TYPE_BYTES | 0x45, 202 /** 203 * A tag whose value is the uint32 type indicating the additional action. 204 * 205 * @since 12 206 */ 207 ASSET_TAG_OPERATION_TYPE = ASSET_TYPE_NUMBER | 0x46, 208 } Asset_Tag; 209 210 /** 211 * @brief Enumerates the result codes used in the ASSET APIs. 212 * 213 * @since 11 214 */ 215 typedef enum { 216 /** @error The operation is successful. */ 217 ASSET_SUCCESS = 0, 218 /** @error The caller doesn't have the permission. */ 219 ASSET_PERMISSION_DENIED = 201, 220 /** @error The parameter is invalid. */ 221 ASSET_INVALID_ARGUMENT = 401, 222 /** @error The ASSET service is unavailable. */ 223 ASSET_SERVICE_UNAVAILABLE = 24000001, 224 /** @error The asset is not found. */ 225 ASSET_NOT_FOUND = 24000002, 226 /** @error The asset already exists. */ 227 ASSET_DUPLICATED = 24000003, 228 /** @error Access to the asset is denied. */ 229 ASSET_ACCESS_DENIED = 24000004, 230 /** @error The screen lock status does not match. */ 231 ASSET_STATUS_MISMATCH = 24000005, 232 /** @error Insufficient memory. */ 233 ASSET_OUT_OF_MEMORY = 24000006, 234 /** @error The asset is corrupted. */ 235 ASSET_DATA_CORRUPTED = 24000007, 236 /** @error The database operation failed. */ 237 ASSET_DATABASE_ERROR = 24000008, 238 /** @error The cryptography operation failed. */ 239 ASSET_CRYPTO_ERROR = 24000009, 240 /** @error IPC failed. */ 241 ASSET_IPC_ERROR = 24000010, 242 /** @error Calling the Bundle Manager service failed. */ 243 ASSET_BMS_ERROR = 24000011, 244 /** @error Calling the OS Account service failed. */ 245 ASSET_ACCOUNT_ERROR = 24000012, 246 /** @error Calling the Access Token service failed. */ 247 ASSET_ACCESS_TOKEN_ERROR = 24000013, 248 /** @error The file operation failed. */ 249 ASSET_FILE_OPERATION_ERROR = 24000014, 250 /** @error Getting the system time failed. */ 251 ASSET_GET_SYSTEM_TIME_ERROR = 24000015, 252 /** @error The cache exceeds the limit. */ 253 ASSET_LIMIT_EXCEEDED = 24000016, 254 /** @error The capability is not supported. */ 255 ASSET_UNSUPPORTED = 24000017, 256 } Asset_ResultCode; 257 258 /** 259 * @brief Enumerates the types of the access control based on the lock screen status. 260 * 261 * @since 11 262 */ 263 typedef enum { 264 /** 265 * The asset can be accessed after the device is powered on. 266 */ 267 ASSET_ACCESSIBILITY_DEVICE_POWERED_ON = 0, 268 /** 269 * The asset can be accessed only after the device is unlocked for the first time. 270 */ 271 ASSET_ACCESSIBILITY_DEVICE_FIRST_UNLOCKED = 1, 272 /** 273 * The asset can be accessed only after the device is unlocked. 274 */ 275 ASSET_ACCESSIBILITY_DEVICE_UNLOCKED = 2, 276 } Asset_Accessibility; 277 278 /** 279 * @brief Enumerates the user authentication types supported for assets. 280 * 281 * @since 11 282 */ 283 typedef enum { 284 /** 285 * No user authentication is required before the asset is accessed. 286 */ 287 ASSET_AUTH_TYPE_NONE = 0x00, 288 /** 289 * The asset can be accessed if any user authentication (such as PIN, facial, or fingerprint authentication) is 290 * successful. 291 */ 292 ASSET_AUTH_TYPE_ANY = 0xFF, 293 } Asset_AuthType; 294 295 /** 296 * @brief Enumerates the asset synchronization types. 297 * 298 * @since 11 299 */ 300 typedef enum { 301 /** 302 * Asset synchronization is not allowed. 303 */ 304 ASSET_SYNC_TYPE_NEVER = 0, 305 /** 306 * Asset synchronization is allowed only on the local device, for example, in data restoration on the local device. 307 */ 308 ASSET_SYNC_TYPE_THIS_DEVICE = 1 << 0, 309 /** 310 * Asset synchronization is allowed only between trusted devices, for example, in the case of cloning. 311 */ 312 ASSET_SYNC_TYPE_TRUSTED_DEVICE = 1 << 1, 313 /** 314 * Asset synchronization is allowed only between devices with trusted accounts. 315 * 316 * @since 12 317 */ 318 ASSET_SYNC_TYPE_TRUSTED_ACCOUNT = 1 << 2, 319 } Asset_SyncType; 320 321 /** 322 * @brief Enumerates the policies for resolving the conflict (for example, duplicate alias) occurred when 323 * an asset is added. 324 * 325 * @since 11 326 */ 327 typedef enum { 328 /** 329 * Overwrite the existing asset. 330 */ 331 ASSET_CONFLICT_OVERWRITE = 0, 332 /** 333 * Throw an exception for the service to perform subsequent processing. 334 */ 335 ASSET_CONFLICT_THROW_ERROR = 1, 336 } Asset_ConflictResolution; 337 338 /** 339 * @brief Enumerates the types of the asset query result. 340 * 341 * @since 11 342 */ 343 typedef enum { 344 /** 345 * The query result contains the asset in plaintext and its attributes. 346 */ 347 ASSET_RETURN_ALL = 0, 348 /** 349 * The query result contains only the asset attributes. 350 */ 351 ASSET_RETURN_ATTRIBUTES = 1, 352 } Asset_ReturnType; 353 354 /** 355 * @brief Enumerates the types of the additional action. 356 * 357 * @since 12 358 */ 359 typedef enum { 360 /** 361 * Synchronization is required during operation. 362 */ 363 ASSET_NEED_SYNC = 0, 364 /** 365 * Logout is required during operation. 366 */ 367 ASSET_NEED_LOGOUT = 1, 368 } Asset_OperationType; 369 370 /** 371 * @brief Defines an asset value in the forma of a binary array, that is, a variable-length byte array. 372 * 373 * @since 11 374 */ 375 typedef struct { 376 /** 377 * Size of the byte array. 378 */ 379 uint32_t size; 380 /** 381 * Pointer to the byte array. 382 */ 383 uint8_t *data; 384 } Asset_Blob; 385 386 /** 387 * @brief Defines the value (content) of an asset attribute. 388 * 389 * @since 11 390 */ 391 typedef union { 392 /** 393 * Asset of the Boolean type. 394 */ 395 bool boolean; 396 /** 397 * Asset of the uint32 type. 398 */ 399 uint32_t u32; 400 /** 401 * Asset of the bytes type. 402 */ 403 Asset_Blob blob; 404 } Asset_Value; 405 406 /** 407 * @brief Defines an asset attribute. 408 * 409 * @since 11 410 */ 411 typedef struct { 412 /** 413 * Tag of the asset attribute. 414 */ 415 uint32_t tag; 416 /** 417 * Value of the asset attribute. 418 */ 419 Asset_Value value; 420 } Asset_Attr; 421 422 /** 423 * @brief Represents information about an asset. 424 * 425 * @since 11 426 */ 427 typedef struct { 428 /** 429 * Number of asset attributes. 430 */ 431 uint32_t count; 432 /** 433 * Pointer to the array of the asset attributes. 434 */ 435 Asset_Attr *attrs; 436 } Asset_Result; 437 438 /** 439 * @brief Represents information about a set of assets. 440 * 441 * @since 11 442 */ 443 typedef struct { 444 /** 445 * Number of assets. 446 */ 447 uint32_t count; 448 /** 449 * Pointer to the array of the assets. 450 */ 451 Asset_Result *results; 452 } Asset_ResultSet; 453 454 #ifdef __cplusplus 455 } 456 #endif 457 458 /** @} */ 459 #endif // ASSET_TYPE_H