1 /* 2 * Copyright (c) 2022 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. */ 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 /** Freezing time, the value type is int32_t. */ 57 ATTR_FREEZING_TIME = 100010, 58 /** Session ID, the value type is uint64_t. */ 59 ATTR_SESSION_ID = 100014, 60 /** Schedule version, the value type is uint32_t. */ 61 ATTR_SCHEDULE_VERSION = 100016, 62 /** Schedule ID, the value type is uint64_t. */ 63 ATTR_SCHEDULE_ID = 100020, 64 /** Pin subtype, the value type is int32_t. */ 65 ATTR_PIN_SUB_TYPE = 100021, 66 /** Schedule mode, the value type is int32_t. */ 67 ATTR_SCHEDULE_MODE = 100022, 68 /** Property mode, the value type is uint32_t. */ 69 ATTR_PROPERTY_MODE = 100023, 70 /** Authenticate type, the value type is int32_t. */ 71 ATTR_AUTH_TYPE = 100024, 72 /** Credential ID, the value type is uint64_t. */ 73 ATTR_CREDENTIAL_ID = 100025, 74 /** Caller UID, the value type is uint64_t. */ 75 ATTR_CALLER_UID = 100027, 76 /** Tag of result, the value type is std::vector<uint8_t>. */ 77 ATTR_RESULT = 100028, 78 /** Capability level, the value type is uint64_t. */ 79 ATTR_CAPABILITY_LEVEL = 100029, 80 /** Algorithm infomation, the value type is uint64_t. */ 81 ATTR_ALGORITHM_INFO = 100030, 82 /** Timer stamp, the value type is uint64_t. */ 83 ATTR_TIME_STAMP = 100031, 84 /** Root secret, the value type is std::vector<uint8_t>. */ 85 ATTR_ROOT_SECRET = 100032, 86 /** Auth token, the value type is std::vector<uint8_t>. */ 87 ATTR_AUTH_TOKEN = 100033, 88 /** Security user id return when add pin credential, the value type is uint64_t. */ 89 ATTR_SEC_USER_ID = 100034, 90 /** Enroll progress, the value type is string. */ 91 ATTR_ENROLL_PROGRESS = 100035, 92 /** Sensor info, the value type is string. */ 93 ATTR_SENSOR_INFO = 100036, 94 /** Key list, the value type is std::vector<uint32_t>. */ 95 ATTR_KEY_LIST = 100037, 96 /** End after first fail, the value type is boolean. */ 97 ATTR_END_AFTER_FIRST_FAIL = 100038, 98 /** tip info, the value type is int32_t. */ 99 ATTR_TIP_INFO = 100039, 100 /** 101 * Private attrs. 102 * User ID, the value type is int32_t. 103 */ 104 ATTR_USER_ID = 300000, 105 /** Extra infomation, the value type is std::vector<uint8_t>. */ 106 ATTR_EXTRA_INFO, 107 /** Executor ID, the value type is uint64_t. */ 108 ATTR_EXECUTOR_INDEX, 109 /** ExecutorSensorHint, the value type is uint32_t. */ 110 ATTR_EXECUTOR_SENSOR_HINT, 111 /** ExecutorMatcher, the value type is uint32_t. */ 112 ATTR_EXECUTOR_MATCHER, 113 /** Access token ID, the value type is uint32_t. */ 114 ATTR_ACCESS_TOKEN_ID, 115 /** Template change reason, the value type is string */ 116 ATTR_TEMPLATE_CHANGE_REASON, 117 }; 118 119 /** 120 * @brief Default constructor. 121 */ 122 Attributes(); 123 124 /** 125 * @brief Overload constructor. 126 * 127 * This constructor prohibits implicit type conversion of input parameters. 128 * 129 * @param raw The value to be passed in when defining Attribute. 130 */ 131 explicit Attributes(const std::vector<uint8_t> &raw); 132 133 /** 134 * @brief Overload constructor. 135 * 136 * This constructor is used to define constant Attribute type. 137 * 138 * @param other The value to be passed in when defining Attribute. 139 */ 140 Attributes(const Attributes &other) = delete; 141 142 /** 143 * @brief Overload operator. 144 * 145 * @param other The value to be compared. 146 */ 147 Attributes &operator=(const Attributes &other) = delete; 148 149 /** 150 * @brief Overload constructor. 151 * 152 * @param other The value to be passed in when defining Attribute. 153 */ 154 Attributes(Attributes &&other) noexcept; 155 156 /** 157 * @brief Overload operator. 158 * 159 * @param other The value to be compared. 160 */ 161 Attributes &operator=(Attributes &&other) noexcept; 162 163 /** 164 * @brief Deconstructor. 165 */ 166 virtual ~Attributes(); 167 168 /** 169 * @brief Set bool value. 170 * 171 * @param key The attribute key. 172 * @param value The bool value. 173 * @return Return success or not(true:success; false:failed). 174 */ 175 bool SetBoolValue(AttributeKey key, bool value); 176 177 /** 178 * @brief Set uint64 value. 179 * 180 * @param key The attribute key. 181 * @param value The uint64_t value. 182 * @return Return success or not(true:success; false:failed). 183 */ 184 bool SetUint64Value(AttributeKey key, uint64_t value); 185 186 /** 187 * @brief Set uint32_t value. 188 * 189 * @param key The attribute key. 190 * @param value The uint32_t value. 191 * @return Return success or not(true:success; false:failed). 192 */ 193 bool SetUint32Value(AttributeKey key, uint32_t value); 194 195 /** 196 * @brief Set uint16_t value. 197 * 198 * @param key The attribute key. 199 * @param value The uint16_t value. 200 * @return Return success or not(true:success; false:failed). 201 */ 202 bool SetUint16Value(AttributeKey key, uint16_t value); 203 204 /** 205 * @brief Set uint8_t value. 206 * 207 * @param key The attribute key. 208 * @param value The uint8_t value. 209 * @return Return success or not(true:success; false:failed). 210 */ 211 bool SetUint8Value(AttributeKey key, uint8_t value); 212 213 /** 214 * @brief Set int32_t value. 215 * 216 * @param key The attribute key. 217 * @param value The int32_t value. 218 * @return Return success or not(true:success; false:failed). 219 */ 220 bool SetInt32Value(AttributeKey key, int32_t value); 221 222 /** 223 * @brief Set string value. 224 * 225 * @param key The attribute key. 226 * @param value The string. 227 * @return Return success or not(true:success; false:failed). 228 */ 229 bool SetStringValue(AttributeKey key, const std::string &value); 230 231 /** 232 * @brief Set Attributes value. 233 * 234 * @param key The attribute key. 235 * @param value The attributes type value. 236 * @return Return success or not(true:success; false:failed). 237 */ 238 bool SetAttributesValue(AttributeKey key, const Attributes &value); 239 240 /** 241 * @brief Set vector<uint64_t> value. 242 * 243 * @param key The attribute key. 244 * @param value The vector<uint64_t> value. 245 * @return Return success or not(true:success; false:failed). 246 */ 247 bool SetUint64ArrayValue(AttributeKey key, const std::vector<uint64_t> &value); 248 249 /** 250 * @brief Set vector<uint32_t> value. 251 * 252 * @param key The attribute key. 253 * @param value The vector<uint32_t> value. 254 * @return Return success or not(true:success; false:failed). 255 */ 256 bool SetUint32ArrayValue(AttributeKey key, const std::vector<uint32_t> &value); 257 258 /** 259 * @brief Set vector<uint16_t> value. 260 * 261 * @param key The attribute key. 262 * @param value The vector<uint16_t> value. 263 * @return Return success or not(true:success; false:failed). 264 */ 265 bool SetUint16ArrayValue(AttributeKey key, const std::vector<uint16_t> &value); 266 267 /** 268 * @brief Set vector<uint8_t> value. 269 * 270 * @param key The attribute key. 271 * @param value The vector<uint8_t> value. 272 * @return Return success or not(true:success; false:failed). 273 */ 274 bool SetUint8ArrayValue(AttributeKey key, const std::vector<uint8_t> &value); 275 276 /** 277 * @brief Get bool value. 278 * 279 * @param key The attribute key. 280 * @param value Return bool value corresponding to key. 281 * @return Return success or not(true:success; false:failed). 282 */ 283 bool GetBoolValue(AttributeKey key, bool &value) const; 284 285 /** 286 * @brief Get uint64_t value. 287 * 288 * @param key The attribute key. 289 * @param value Return uint64_t value corresponding to key. 290 * @return Return success or not(true:success; false:failed). 291 */ 292 bool GetUint64Value(AttributeKey key, uint64_t &value) const; 293 294 /** 295 * @brief Get uint32_t value. 296 * 297 * @param key The attribute key. 298 * @param value Return uint32_t value corresponding to key. 299 * @return Return success or not(true:success; false:failed). 300 */ 301 bool GetUint32Value(AttributeKey key, uint32_t &value) const; 302 303 /** 304 * @brief Get uint16_t value. 305 * 306 * @param key The attribute key. 307 * @param value Return uint16_t value corresponding to key. 308 * @return Return success or not(true:success; false:failed). 309 */ 310 bool GetUint16Value(AttributeKey key, uint16_t &value) const; 311 312 /** 313 * @brief Get uint8_t value. 314 * 315 * @param key The attribute key. 316 * @param value Return uint8_t value corresponding to key. 317 * @return Return success or not(true:success; false:failed). 318 */ 319 bool GetUint8Value(AttributeKey key, uint8_t &value) const; 320 321 /** 322 * @brief Get int32_t value. 323 * 324 * @param key The attribute key. 325 * @param value Return int32_t value corresponding to key. 326 * @return Return success or not(true:success; false:failed). 327 */ 328 bool GetInt32Value(AttributeKey key, int32_t &value) const; 329 330 /** 331 * @brief Get string value. 332 * 333 * @param key The attribute key. 334 * @param value Return string corresponding to key. 335 * @return Return success or not(true:success; false:failed). 336 */ 337 bool GetStringValue(AttributeKey key, std::string &value) const; 338 339 /** 340 * @brief Get vector<uint64_t> value. 341 * 342 * @param key The attribute key. 343 * @param value Return vector<uint64_t> value corresponding to key. 344 * @return Return success or not(true:success; false:failed). 345 */ 346 bool GetUint64ArrayValue(AttributeKey key, std::vector<uint64_t> &value) const; 347 348 /** 349 * @brief Get vector<uint32_t> value. 350 * 351 * @param key The attribute key. 352 * @param value Return vector<uint32_t> value corresponding to key. 353 * @return Return success or not(true:success; false:failed). 354 */ 355 bool GetUint32ArrayValue(AttributeKey key, std::vector<uint32_t> &value) const; 356 357 /** 358 * @brief Get vector<uint16_t> value. 359 * 360 * @param key The attribute key. 361 * @param value Return vector<uint16_t> value corresponding to key. 362 * @return Return success or not(true:success; false:failed). 363 */ 364 bool GetUint16ArrayValue(AttributeKey key, std::vector<uint16_t> &value) const; 365 366 /** 367 * @brief Get vector<uint8_t> value. 368 * 369 * @param key The attribute key. 370 * @param value Return vector<uint8_t> value corresponding to key. 371 * @return Return success or not(true:success; false:failed). 372 */ 373 bool GetUint8ArrayValue(AttributeKey key, std::vector<uint8_t> &value) const; 374 375 /** 376 * @brief Get Attributes value. 377 * 378 * @param key The attribute key. 379 * @param value Return Attributes value corresponding to key. 380 * @return Return success or not(true:success; false:failed). 381 */ 382 bool GetAttributesValue(AttributeKey key, Attributes &value) const; 383 384 /** 385 * @brief Serialize the Attribute object. 386 * 387 * @return Return serialized Attribute object. 388 */ 389 std::vector<uint8_t> Serialize() const; 390 391 /** 392 * @brief Get all keys of Attribute. 393 * 394 * @return Return all keys of Attribute. 395 */ 396 std::vector<AttributeKey> GetKeys() const; 397 398 private: 399 class Impl; 400 std::unique_ptr<Impl> impl_; 401 }; 402 } // namespace UserAuth 403 } // namespace UserIam 404 } // namespace OHOS 405 406 #endif // IAM_ATTRIBUTES_H 407