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 /* credential length, the value type is uint32_t. */ 207 ATTR_CREDENTIAL_LENGTH = 100092, 208 }; 209 210 /** 211 * @brief Default constructor. 212 */ 213 Attributes(); 214 215 /** 216 * @brief Overload constructor. 217 * 218 * This constructor prohibits implicit type conversion of input parameters. 219 * 220 * @param raw The value to be passed in when defining Attribute. 221 */ 222 explicit Attributes(const std::vector<uint8_t> &raw); 223 224 /** 225 * @brief Overload constructor. 226 * 227 * This constructor is used to define constant Attribute type. 228 * 229 * @param other The value to be passed in when defining Attribute. 230 */ 231 Attributes(const Attributes &other) = delete; 232 233 /** 234 * @brief Overload operator. 235 * 236 * @param other The value to be compared. 237 */ 238 Attributes &operator=(const Attributes &other) = delete; 239 240 /** 241 * @brief Overload constructor. 242 * 243 * @param other The value to be passed in when defining Attribute. 244 */ 245 Attributes(Attributes &&other) noexcept; 246 247 /** 248 * @brief Overload operator. 249 * 250 * @param other The value to be compared. 251 */ 252 Attributes &operator=(Attributes &&other) noexcept; 253 254 /** 255 * @brief Deconstructor. 256 */ 257 virtual ~Attributes(); 258 259 /** 260 * @brief Set bool value. 261 * 262 * @param key The attribute key. 263 * @param value The bool value. 264 * @return Return success or not(true:success; false:failed). 265 */ 266 bool SetBoolValue(AttributeKey key, bool value); 267 268 /** 269 * @brief Set uint64 value. 270 * 271 * @param key The attribute key. 272 * @param value The uint64_t value. 273 * @return Return success or not(true:success; false:failed). 274 */ 275 bool SetUint64Value(AttributeKey key, uint64_t value); 276 277 /** 278 * @brief Set uint32_t value. 279 * 280 * @param key The attribute key. 281 * @param value The uint32_t value. 282 * @return Return success or not(true:success; false:failed). 283 */ 284 bool SetUint32Value(AttributeKey key, uint32_t value); 285 286 /** 287 * @brief Set uint16_t value. 288 * 289 * @param key The attribute key. 290 * @param value The uint16_t value. 291 * @return Return success or not(true:success; false:failed). 292 */ 293 bool SetUint16Value(AttributeKey key, uint16_t value); 294 295 /** 296 * @brief Set uint8_t value. 297 * 298 * @param key The attribute key. 299 * @param value The uint8_t value. 300 * @return Return success or not(true:success; false:failed). 301 */ 302 bool SetUint8Value(AttributeKey key, uint8_t value); 303 304 /** 305 * @brief Set int32_t value. 306 * 307 * @param key The attribute key. 308 * @param value The int32_t value. 309 * @return Return success or not(true:success; false:failed). 310 */ 311 bool SetInt32Value(AttributeKey key, int32_t value); 312 313 /** 314 * @brief Set int64_t value. 315 * 316 * @param key The attribute key. 317 * @param value The int64_t value. 318 * @return Return success or not(true:success; false:failed). 319 */ 320 bool SetInt64Value(AttributeKey key, int64_t value); 321 322 /** 323 * @brief Set string value. 324 * 325 * @param key The attribute key. 326 * @param value The string. 327 * @return Return success or not(true:success; false:failed). 328 */ 329 bool SetStringValue(AttributeKey key, const std::string &value); 330 331 /** 332 * @brief Set Attributes value. 333 * 334 * @param key The attribute key. 335 * @param value The attributes type value. 336 * @return Return success or not(true:success; false:failed). 337 */ 338 bool SetAttributesValue(AttributeKey key, const Attributes &value); 339 bool SetAttributesArrayValue(AttributeKey key, const std::vector<Attributes> &array); 340 341 /** 342 * @brief Set vector<uint64_t> value. 343 * 344 * @param key The attribute key. 345 * @param value The vector<uint64_t> value. 346 * @return Return success or not(true:success; false:failed). 347 */ 348 bool SetUint64ArrayValue(AttributeKey key, const std::vector<uint64_t> &value); 349 350 /** 351 * @brief Set vector<uint32_t> value. 352 * 353 * @param key The attribute key. 354 * @param value The vector<uint32_t> value. 355 * @return Return success or not(true:success; false:failed). 356 */ 357 bool SetUint32ArrayValue(AttributeKey key, const std::vector<uint32_t> &value); 358 359 /** 360 * @brief Set vector<uint32_t> value. 361 * 362 * @param key The attribute key. 363 * @param value The vector<uint32_t> value. 364 * @return Return success or not(true:success; false:failed). 365 */ 366 bool SetInt32ArrayValue(AttributeKey key, const std::vector<int32_t> &value); 367 368 /** 369 * @brief Set vector<uint16_t> value. 370 * 371 * @param key The attribute key. 372 * @param value The vector<uint16_t> value. 373 * @return Return success or not(true:success; false:failed). 374 */ 375 bool SetUint16ArrayValue(AttributeKey key, const std::vector<uint16_t> &value); 376 377 /** 378 * @brief Set vector<uint8_t> value. 379 * 380 * @param key The attribute key. 381 * @param value The vector<uint8_t> value. 382 * @return Return success or not(true:success; false:failed). 383 */ 384 bool SetUint8ArrayValue(AttributeKey key, const std::vector<uint8_t> &value); 385 386 /** 387 * @brief Get bool value. 388 * 389 * @param key The attribute key. 390 * @param value Return bool value corresponding to key. 391 * @return Return success or not(true:success; false:failed). 392 */ 393 bool GetBoolValue(AttributeKey key, bool &value) const; 394 395 /** 396 * @brief Get uint64_t value. 397 * 398 * @param key The attribute key. 399 * @param value Return uint64_t value corresponding to key. 400 * @return Return success or not(true:success; false:failed). 401 */ 402 bool GetUint64Value(AttributeKey key, uint64_t &value) const; 403 404 /** 405 * @brief Get uint32_t value. 406 * 407 * @param key The attribute key. 408 * @param value Return uint32_t value corresponding to key. 409 * @return Return success or not(true:success; false:failed). 410 */ 411 bool GetUint32Value(AttributeKey key, uint32_t &value) const; 412 413 /** 414 * @brief Get uint16_t value. 415 * 416 * @param key The attribute key. 417 * @param value Return uint16_t value corresponding to key. 418 * @return Return success or not(true:success; false:failed). 419 */ 420 bool GetUint16Value(AttributeKey key, uint16_t &value) const; 421 422 /** 423 * @brief Get uint8_t value. 424 * 425 * @param key The attribute key. 426 * @param value Return uint8_t value corresponding to key. 427 * @return Return success or not(true:success; false:failed). 428 */ 429 bool GetUint8Value(AttributeKey key, uint8_t &value) const; 430 431 /** 432 * @brief Get int32_t value. 433 * 434 * @param key The attribute key. 435 * @param value Return int32_t value corresponding to key. 436 * @return Return success or not(true:success; false:failed). 437 */ 438 bool GetInt32Value(AttributeKey key, int32_t &value) const; 439 440 /** 441 * @brief Get int64_t value. 442 * 443 * @param key The attribute key. 444 * @param value Return int64_t value corresponding to key. 445 * @return Return success or not(true:success; false:failed). 446 */ 447 bool GetInt64Value(AttributeKey key, int64_t &value) const; 448 449 /** 450 * @brief Get string value. 451 * 452 * @param key The attribute key. 453 * @param value Return string corresponding to key. 454 * @return Return success or not(true:success; false:failed). 455 */ 456 bool GetStringValue(AttributeKey key, std::string &value) const; 457 458 /** 459 * @brief Get vector<uint64_t> value. 460 * 461 * @param key The attribute key. 462 * @param value Return vector<uint64_t> value corresponding to key. 463 * @return Return success or not(true:success; false:failed). 464 */ 465 bool GetUint64ArrayValue(AttributeKey key, std::vector<uint64_t> &value) const; 466 467 /** 468 * @brief Get vector<uint32_t> value. 469 * 470 * @param key The attribute key. 471 * @param value Return vector<uint32_t> value corresponding to key. 472 * @return Return success or not(true:success; false:failed). 473 */ 474 bool GetUint32ArrayValue(AttributeKey key, std::vector<uint32_t> &value) const; 475 476 /** 477 * @brief Get vector<uint32_t> value. 478 * 479 * @param key The attribute key. 480 * @param value Return vector<uint32_t> value corresponding to key. 481 * @return Return success or not(true:success; false:failed). 482 */ 483 bool GetInt32ArrayValue(AttributeKey key, std::vector<int32_t> &value) const; 484 485 /** 486 * @brief Get vector<uint16_t> value. 487 * 488 * @param key The attribute key. 489 * @param value Return vector<uint16_t> value corresponding to key. 490 * @return Return success or not(true:success; false:failed). 491 */ 492 bool GetUint16ArrayValue(AttributeKey key, std::vector<uint16_t> &value) const; 493 494 /** 495 * @brief Get vector<uint8_t> value. 496 * 497 * @param key The attribute key. 498 * @param value Return vector<uint8_t> value corresponding to key. 499 * @return Return success or not(true:success; false:failed). 500 */ 501 bool GetUint8ArrayValue(AttributeKey key, std::vector<uint8_t> &value) const; 502 503 /** 504 * @brief Get Attributes value. 505 * 506 * @param key The attribute key. 507 * @param value Return Attributes value corresponding to key. 508 * @return Return success or not(true:success; false:failed). 509 */ 510 bool GetAttributesValue(AttributeKey key, Attributes &value) const; 511 512 bool GetAttributesArrayValue(AttributeKey key, std::vector<Attributes> &array) const; 513 514 /** 515 * @brief Serialize the Attribute object. 516 * 517 * @return Return serialized Attribute object. 518 */ 519 std::vector<uint8_t> Serialize() const; 520 521 /** 522 * @brief Get all keys of Attribute. 523 * 524 * @return Return all keys of Attribute. 525 */ 526 std::vector<AttributeKey> GetKeys() const; 527 528 private: 529 class Impl; 530 std::unique_ptr<Impl> impl_ {nullptr}; 531 }; 532 } // namespace UserAuth 533 } // namespace UserIam 534 } // namespace OHOS 535 536 #endif // IAM_ATTRIBUTES_H 537