1 /* 2 * Copyright (c) 2022-2024 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 /** 17 * @file attributes.h 18 * 19 * @brief Attributes enum define. 20 * @since 3.1 21 * @version 3.2 22 */ 23 24 #ifndef IAM_ATTRIBUTES_H 25 #define IAM_ATTRIBUTES_H 26 27 #include <memory> 28 #include <string> 29 #include <vector> 30 31 namespace OHOS { 32 namespace UserIam { 33 namespace UserAuth { 34 class Attributes final { 35 public: 36 /** 37 * @brief The key to set attribute. 38 */ 39 enum AttributeKey : uint32_t { 40 /** Root tag, the value type is std::vector<uint8_t>. */ 41 ATTR_ROOT = 100000, 42 /** Result code, the value type is int32_t. */ 43 ATTR_RESULT_CODE = 100001, 44 /** Signature, the value type is std::vector<uint8_t>. */ 45 ATTR_SIGNATURE = 100004, 46 /** Identify mode, the value type is uint32_t. */ 47 ATTR_IDENTIFY_MODE = 100005, 48 /** Template ID, the value type is uint64_t. */ 49 ATTR_TEMPLATE_ID = 100006, 50 /** Template ID list, the value type is std::vector<uint64_t>. */ 51 ATTR_TEMPLATE_ID_LIST = 100007, 52 /** Attribute error count, the value type is int32_t. */ 53 ATTR_ERROR_COUNT = 100008, 54 /** Remain time, the value type is int32_t. */ 55 ATTR_REMAIN_TIMES = 100009, 56 ATTR_REMAIN_ATTEMPTS = ATTR_REMAIN_TIMES, 57 /** Freezing time, the value type is int32_t. */ 58 ATTR_FREEZING_TIME = 100010, 59 ATTR_LOCKOUT_DURATION = ATTR_FREEZING_TIME, 60 /** Session ID, the value type is uint64_t. */ 61 ATTR_SESSION_ID = 100014, 62 /** Caller package name, the value type is string. */ 63 ATTR_CALLER_NAME = 100015, 64 /** Schedule version, the value type is uint32_t. */ 65 ATTR_SCHEDULE_VERSION = 100016, 66 /** Schedule ID, the value type is uint64_t. */ 67 ATTR_SCHEDULE_ID = 100017, 68 /** Locked templates, the value type is std::vector<uint64_t>. */ 69 ATTR_LOCKED_TEMPLATES = 100018, 70 /** Unlocked templates, the value type is std::vector<uint64_t>. */ 71 ATTR_UNLOCKED_TEMPLATES = 100019, 72 /** Data, the value type is std::vector<uint8_t>. */ 73 ATTR_DATA = 100020, 74 /** Pin subtype, the value type is int32_t. */ 75 ATTR_PIN_SUB_TYPE = 100021, 76 /** Schedule mode, the value type is int32_t. */ 77 ATTR_SCHEDULE_MODE = 100022, 78 /** Property mode, the value type is uint32_t. */ 79 ATTR_PROPERTY_MODE = 100023, 80 /** Authenticate type, the value type is int32_t. */ 81 ATTR_AUTH_TYPE = 100024, 82 /** Credential ID, the value type is uint64_t. */ 83 ATTR_CREDENTIAL_ID = 100025, 84 /** Caller UID, the value type is uint64_t. */ 85 ATTR_CALLER_UID = 100027, 86 /** Tag of result, the value type is std::vector<uint8_t>. */ 87 ATTR_RESULT = 100028, 88 /** Capability level, the value type is uint64_t. */ 89 ATTR_CAPABILITY_LEVEL = 100029, 90 /** Algorithm information, the value type is uint64_t. */ 91 ATTR_ALGORITHM_INFO = 100030, 92 /** Timer stamp, the value type is uint64_t. */ 93 ATTR_TIME_STAMP = 100031, 94 /** Root secret, the value type is std::vector<uint8_t>. */ 95 ATTR_ROOT_SECRET = 100032, 96 /** Auth token, the value type is std::vector<uint8_t>. */ 97 ATTR_AUTH_TOKEN = 100033, 98 /** Security user ID return when add pin credential, the value type is uint64_t. */ 99 ATTR_SEC_USER_ID = 100034, 100 /** Enroll progress, the value type is string. */ 101 ATTR_ENROLL_PROGRESS = 100035, 102 /** Sensor info, the value type is string. */ 103 ATTR_SENSOR_INFO = 100036, 104 /** Key list, the value type is std::vector<uint32_t>. */ 105 ATTR_KEY_LIST = 100037, 106 /** End after first fail, the value type is boolean. */ 107 ATTR_END_AFTER_FIRST_FAIL = 100038, 108 /** Tip info, the value type is int32_t. */ 109 ATTR_TIP_INFO = 100039, 110 /** Old root secret, the value type is std::vector<uint8_t>. */ 111 ATTR_OLD_ROOT_SECRET = 100040, 112 /** Old credential ID, the value type is uint64_t. */ 113 ATTR_OLD_CREDENTIAL_ID = 100041, 114 /** Source role, the value type is int32_t. */ 115 ATTR_SRC_ROLE = 100042, 116 /** User ID, the value type is int32_t. */ 117 ATTR_USER_ID = 100043, 118 /** Extra information, the value type is std::vector<uint8_t>. */ 119 ATTR_EXTRA_INFO = 100044, 120 /** Executor ID, the value type is uint64_t. */ 121 ATTR_EXECUTOR_INDEX = 100045, 122 /** Executor sensor hint, the value type is uint32_t. */ 123 ATTR_EXECUTOR_SENSOR_HINT = 100046, 124 /** Executor matcher, the value type is uint32_t. */ 125 ATTR_EXECUTOR_MATCHER = 100047, 126 /** Access token ID, the value type is uint32_t. */ 127 ATTR_ACCESS_TOKEN_ID = 100048, 128 /** Template change reason, the value type is string. */ 129 ATTR_TEMPLATE_CHANGE_REASON = 100049, 130 /** Credential digest, the value type is uint64_t. */ 131 ATTR_CREDENTIAL_DIGEST = 100050, 132 /** Credential count, the value type is uint16_t. */ 133 ATTR_CREDENTIAL_COUNT = 100051, 134 /** Message sequence number, the value type is uint32_t. */ 135 ATTR_MSG_SEQ_NUM = 100052, 136 /** Reply message, the value type is bool. */ 137 ATTR_MSG_ACK = 100053, 138 /** Message source UDID, the value type is string. */ 139 ATTR_MSG_SRC_UDID = 100054, 140 /** Source of message, the value type is string. */ 141 ATTR_MSG_SRC_END_POINT = 100055, 142 /** Destination of message, the value type is string. */ 143 ATTR_MSG_DEST_END_POINT = 100056, 144 /** Connection name, the value type is string. */ 145 ATTR_CONNECTION_NAME = 100057, 146 /** Message version, the value type is uint32_t. */ 147 ATTR_MSG_VERSION = 100058, 148 /** Message type, the value type is int32_t. */ 149 ATTR_MSG_TYPE = 100059, 150 /** Message reply sequence number, the value type is uint32_t. */ 151 ATTR_MSG_REPLY_SEQ_NUM = 100060, 152 /** Context ID, the value type is uint64_t. */ 153 ATTR_CONTEXT_ID = 100061, 154 /** Collector info, the value type is std::vector<uint8_t>. */ 155 ATTR_COLLECTOR_INFO = 100062, 156 /** Executor role, the value type is int32_t. */ 157 ATTR_EXECUTOR_ROLE = 100063, 158 /** Schedule data, the value type is std::vector<uint8_t>. */ 159 ATTR_SCHEDULE_DATA = 100064, 160 /** Signed authentication result, the value type is std::vector<uint8_t>. */ 161 ATTR_SIGNED_AUTH_RESULT = 100065, 162 /** Destination role, the value type is int32_t. */ 163 ATTR_DEST_ROLE = 100066, 164 /** Local UDID, the value type is string. */ 165 ATTR_LOCAL_UDID = 100067, 166 /** Peer UDID, the value type is string. */ 167 ATTR_PEER_UDID = 100068, 168 /** Public key, the value type is std::vector<uint8_t>. */ 169 ATTR_PUBLIC_KEY = 100069, 170 /** Executor info list, the value type is std::vector<uint8_t>. */ 171 ATTR_EXECUTOR_REGISTER_INFO_LIST = 100070, 172 /** Executor secure level, the value type is int32_t. */ 173 ATTR_ESL = 100071, 174 /** Challenge, the value type is std::vector<uint8_t>. */ 175 ATTR_CHALLENGE = 100072, 176 /** Remote executor info, the value type is std::vector<uint8_t>. */ 177 ATTR_REMOTE_EXECUTOR_INFO = 100073, 178 /** Authentication types, the value type is std::vector<int32_t>. */ 179 ATTR_AUTH_TYPES = 100074, 180 /** Authentication trust level, the value type is int32_t. */ 181 ATTR_AUTH_TRUST_LEVEL = 100075, 182 /** Device UDID, the value type is string. */ 183 ATTR_DEVICE_UDID = 100080, 184 /** Collector network id. */ 185 ATTR_COLLECTOR_NETWORK_ID = 100081, 186 /** Collector token id. */ 187 ATTR_COLLECTOR_TOKEN_ID = 100082, 188 /** Pin expired info, the value type is int64_t and it's max value is 2^50. */ 189 ATTR_PIN_EXPIRED_INFO = 100083, 190 /** next fail lockout duration, the value type is int32_t. */ 191 ATTR_NEXT_FAIL_LOCKOUT_DURATION = 100084, 192 /** caller type, the value type is int32_t. */ 193 ATTR_CALLER_TYPE = 100085, 194 /* auth intention */ 195 ATTR_AUTH_INTENTION = 100086, 196 /** Supported message version, the value type is std::vector<uint32_t>. */ 197 ATTR_SUPPORTED_MSG_VERSION = 100087, 198 /* re-enroll flag, the value type is bool */ 199 ATTR_RE_ENROLL_FLAG = 100088, 200 /* Token version, the value type is uint32_t. */ 201 ATTR_TOKEN_VERSION = 100089, 202 /* Token type of token, the value type is int32_t. */ 203 ATTR_TOKEN_TYPE = 100090, 204 /* Token time interval between sign and verify, the value type is int64_t. */ 205 ATTR_TOKEN_TIME_INTERVAL = 100091, 206 }; 207 208 /** 209 * @brief Default constructor. 210 */ 211 Attributes(); 212 213 /** 214 * @brief Overload constructor. 215 * 216 * This constructor prohibits implicit type conversion of input parameters. 217 * 218 * @param raw The value to be passed in when defining Attribute. 219 */ 220 explicit Attributes(const std::vector<uint8_t> &raw); 221 222 /** 223 * @brief Overload constructor. 224 * 225 * This constructor is used to define constant Attribute type. 226 * 227 * @param other The value to be passed in when defining Attribute. 228 */ 229 Attributes(const Attributes &other) = delete; 230 231 /** 232 * @brief Overload operator. 233 * 234 * @param other The value to be compared. 235 */ 236 Attributes &operator=(const Attributes &other) = delete; 237 238 /** 239 * @brief Overload constructor. 240 * 241 * @param other The value to be passed in when defining Attribute. 242 */ 243 Attributes(Attributes &&other) noexcept; 244 245 /** 246 * @brief Overload operator. 247 * 248 * @param other The value to be compared. 249 */ 250 Attributes &operator=(Attributes &&other) noexcept; 251 252 /** 253 * @brief Deconstructor. 254 */ 255 virtual ~Attributes(); 256 257 /** 258 * @brief Set bool value. 259 * 260 * @param key The attribute key. 261 * @param value The bool value. 262 * @return Return success or not(true:success; false:failed). 263 */ 264 bool SetBoolValue(AttributeKey key, bool value); 265 266 /** 267 * @brief Set uint64 value. 268 * 269 * @param key The attribute key. 270 * @param value The uint64_t value. 271 * @return Return success or not(true:success; false:failed). 272 */ 273 bool SetUint64Value(AttributeKey key, uint64_t value); 274 275 /** 276 * @brief Set uint32_t value. 277 * 278 * @param key The attribute key. 279 * @param value The uint32_t value. 280 * @return Return success or not(true:success; false:failed). 281 */ 282 bool SetUint32Value(AttributeKey key, uint32_t value); 283 284 /** 285 * @brief Set uint16_t value. 286 * 287 * @param key The attribute key. 288 * @param value The uint16_t value. 289 * @return Return success or not(true:success; false:failed). 290 */ 291 bool SetUint16Value(AttributeKey key, uint16_t value); 292 293 /** 294 * @brief Set uint8_t value. 295 * 296 * @param key The attribute key. 297 * @param value The uint8_t value. 298 * @return Return success or not(true:success; false:failed). 299 */ 300 bool SetUint8Value(AttributeKey key, uint8_t value); 301 302 /** 303 * @brief Set int32_t value. 304 * 305 * @param key The attribute key. 306 * @param value The int32_t value. 307 * @return Return success or not(true:success; false:failed). 308 */ 309 bool SetInt32Value(AttributeKey key, int32_t value); 310 311 /** 312 * @brief Set int64_t value. 313 * 314 * @param key The attribute key. 315 * @param value The int64_t value. 316 * @return Return success or not(true:success; false:failed). 317 */ 318 bool SetInt64Value(AttributeKey key, int64_t value); 319 320 /** 321 * @brief Set string value. 322 * 323 * @param key The attribute key. 324 * @param value The string. 325 * @return Return success or not(true:success; false:failed). 326 */ 327 bool SetStringValue(AttributeKey key, const std::string &value); 328 329 /** 330 * @brief Set Attributes value. 331 * 332 * @param key The attribute key. 333 * @param value The attributes type value. 334 * @return Return success or not(true:success; false:failed). 335 */ 336 bool SetAttributesValue(AttributeKey key, const Attributes &value); 337 bool SetAttributesArrayValue(AttributeKey key, const std::vector<Attributes> &array); 338 339 /** 340 * @brief Set vector<uint64_t> value. 341 * 342 * @param key The attribute key. 343 * @param value The vector<uint64_t> value. 344 * @return Return success or not(true:success; false:failed). 345 */ 346 bool SetUint64ArrayValue(AttributeKey key, const std::vector<uint64_t> &value); 347 348 /** 349 * @brief Set vector<uint32_t> value. 350 * 351 * @param key The attribute key. 352 * @param value The vector<uint32_t> value. 353 * @return Return success or not(true:success; false:failed). 354 */ 355 bool SetUint32ArrayValue(AttributeKey key, const std::vector<uint32_t> &value); 356 357 /** 358 * @brief Set vector<uint32_t> value. 359 * 360 * @param key The attribute key. 361 * @param value The vector<uint32_t> value. 362 * @return Return success or not(true:success; false:failed). 363 */ 364 bool SetInt32ArrayValue(AttributeKey key, const std::vector<int32_t> &value); 365 366 /** 367 * @brief Set vector<uint16_t> value. 368 * 369 * @param key The attribute key. 370 * @param value The vector<uint16_t> value. 371 * @return Return success or not(true:success; false:failed). 372 */ 373 bool SetUint16ArrayValue(AttributeKey key, const std::vector<uint16_t> &value); 374 375 /** 376 * @brief Set vector<uint8_t> value. 377 * 378 * @param key The attribute key. 379 * @param value The vector<uint8_t> value. 380 * @return Return success or not(true:success; false:failed). 381 */ 382 bool SetUint8ArrayValue(AttributeKey key, const std::vector<uint8_t> &value); 383 384 /** 385 * @brief Get bool value. 386 * 387 * @param key The attribute key. 388 * @param value Return bool value corresponding to key. 389 * @return Return success or not(true:success; false:failed). 390 */ 391 bool GetBoolValue(AttributeKey key, bool &value) const; 392 393 /** 394 * @brief Get uint64_t value. 395 * 396 * @param key The attribute key. 397 * @param value Return uint64_t value corresponding to key. 398 * @return Return success or not(true:success; false:failed). 399 */ 400 bool GetUint64Value(AttributeKey key, uint64_t &value) const; 401 402 /** 403 * @brief Get uint32_t value. 404 * 405 * @param key The attribute key. 406 * @param value Return uint32_t value corresponding to key. 407 * @return Return success or not(true:success; false:failed). 408 */ 409 bool GetUint32Value(AttributeKey key, uint32_t &value) const; 410 411 /** 412 * @brief Get uint16_t value. 413 * 414 * @param key The attribute key. 415 * @param value Return uint16_t value corresponding to key. 416 * @return Return success or not(true:success; false:failed). 417 */ 418 bool GetUint16Value(AttributeKey key, uint16_t &value) const; 419 420 /** 421 * @brief Get uint8_t value. 422 * 423 * @param key The attribute key. 424 * @param value Return uint8_t value corresponding to key. 425 * @return Return success or not(true:success; false:failed). 426 */ 427 bool GetUint8Value(AttributeKey key, uint8_t &value) const; 428 429 /** 430 * @brief Get int32_t value. 431 * 432 * @param key The attribute key. 433 * @param value Return int32_t value corresponding to key. 434 * @return Return success or not(true:success; false:failed). 435 */ 436 bool GetInt32Value(AttributeKey key, int32_t &value) const; 437 438 /** 439 * @brief Get int64_t value. 440 * 441 * @param key The attribute key. 442 * @param value Return int64_t value corresponding to key. 443 * @return Return success or not(true:success; false:failed). 444 */ 445 bool GetInt64Value(AttributeKey key, int64_t &value) const; 446 447 /** 448 * @brief Get string value. 449 * 450 * @param key The attribute key. 451 * @param value Return string corresponding to key. 452 * @return Return success or not(true:success; false:failed). 453 */ 454 bool GetStringValue(AttributeKey key, std::string &value) const; 455 456 /** 457 * @brief Get vector<uint64_t> value. 458 * 459 * @param key The attribute key. 460 * @param value Return vector<uint64_t> value corresponding to key. 461 * @return Return success or not(true:success; false:failed). 462 */ 463 bool GetUint64ArrayValue(AttributeKey key, std::vector<uint64_t> &value) const; 464 465 /** 466 * @brief Get vector<uint32_t> value. 467 * 468 * @param key The attribute key. 469 * @param value Return vector<uint32_t> value corresponding to key. 470 * @return Return success or not(true:success; false:failed). 471 */ 472 bool GetUint32ArrayValue(AttributeKey key, std::vector<uint32_t> &value) const; 473 474 /** 475 * @brief Get vector<uint32_t> value. 476 * 477 * @param key The attribute key. 478 * @param value Return vector<uint32_t> value corresponding to key. 479 * @return Return success or not(true:success; false:failed). 480 */ 481 bool GetInt32ArrayValue(AttributeKey key, std::vector<int32_t> &value) const; 482 483 /** 484 * @brief Get vector<uint16_t> value. 485 * 486 * @param key The attribute key. 487 * @param value Return vector<uint16_t> value corresponding to key. 488 * @return Return success or not(true:success; false:failed). 489 */ 490 bool GetUint16ArrayValue(AttributeKey key, std::vector<uint16_t> &value) const; 491 492 /** 493 * @brief Get vector<uint8_t> value. 494 * 495 * @param key The attribute key. 496 * @param value Return vector<uint8_t> value corresponding to key. 497 * @return Return success or not(true:success; false:failed). 498 */ 499 bool GetUint8ArrayValue(AttributeKey key, std::vector<uint8_t> &value) const; 500 501 /** 502 * @brief Get Attributes value. 503 * 504 * @param key The attribute key. 505 * @param value Return Attributes value corresponding to key. 506 * @return Return success or not(true:success; false:failed). 507 */ 508 bool GetAttributesValue(AttributeKey key, Attributes &value) const; 509 510 bool GetAttributesArrayValue(AttributeKey key, std::vector<Attributes> &array) const; 511 512 /** 513 * @brief Serialize the Attribute object. 514 * 515 * @return Return serialized Attribute object. 516 */ 517 std::vector<uint8_t> Serialize() const; 518 519 /** 520 * @brief Get all keys of Attribute. 521 * 522 * @return Return all keys of Attribute. 523 */ 524 std::vector<AttributeKey> GetKeys() const; 525 526 private: 527 class Impl; 528 std::unique_ptr<Impl> impl_ {nullptr}; 529 }; 530 } // namespace UserAuth 531 } // namespace UserIam 532 } // namespace OHOS 533 534 #endif // IAM_ATTRIBUTES_H 535