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 }; 116 117 /** 118 * @brief Default constructor. 119 */ 120 Attributes(); 121 122 /** 123 * @brief Overload constructor. 124 * 125 * This constructor prohibits implicit type conversion of input parameters. 126 * 127 * @param raw The value to be passed in when defining Attribute. 128 */ 129 explicit Attributes(const std::vector<uint8_t> &raw); 130 131 /** 132 * @brief Overload constructor. 133 * 134 * This constructor is used to define constant Attribute type. 135 * 136 * @param other The value to be passed in when defining Attribute. 137 */ 138 Attributes(const Attributes &other) = delete; 139 140 /** 141 * @brief Overload operator. 142 * 143 * @param other The value to be compared. 144 */ 145 Attributes &operator=(const Attributes &other) = delete; 146 147 /** 148 * @brief Overload constructor. 149 * 150 * @param other The value to be passed in when defining Attribute. 151 */ 152 Attributes(Attributes &&other) noexcept; 153 154 /** 155 * @brief Overload operator. 156 * 157 * @param other The value to be compared. 158 */ 159 Attributes &operator=(Attributes &&other) noexcept; 160 161 /** 162 * @brief Deconstructor. 163 */ 164 virtual ~Attributes(); 165 166 /** 167 * @brief Set bool value. 168 * 169 * @param key The attribute key. 170 * @param value The bool value. 171 * @return Return success or not(true:success; false:failed). 172 */ 173 bool SetBoolValue(AttributeKey key, bool value); 174 175 /** 176 * @brief Set uint64 value. 177 * 178 * @param key The attribute key. 179 * @param value The uint64_t value. 180 * @return Return success or not(true:success; false:failed). 181 */ 182 bool SetUint64Value(AttributeKey key, uint64_t value); 183 184 /** 185 * @brief Set uint32_t value. 186 * 187 * @param key The attribute key. 188 * @param value The uint32_t value. 189 * @return Return success or not(true:success; false:failed). 190 */ 191 bool SetUint32Value(AttributeKey key, uint32_t value); 192 193 /** 194 * @brief Set uint16_t value. 195 * 196 * @param key The attribute key. 197 * @param value The uint16_t value. 198 * @return Return success or not(true:success; false:failed). 199 */ 200 bool SetUint16Value(AttributeKey key, uint16_t value); 201 202 /** 203 * @brief Set uint8_t value. 204 * 205 * @param key The attribute key. 206 * @param value The uint8_t value. 207 * @return Return success or not(true:success; false:failed). 208 */ 209 bool SetUint8Value(AttributeKey key, uint8_t value); 210 211 /** 212 * @brief Set int32_t value. 213 * 214 * @param key The attribute key. 215 * @param value The int32_t value. 216 * @return Return success or not(true:success; false:failed). 217 */ 218 bool SetInt32Value(AttributeKey key, int32_t value); 219 220 /** 221 * @brief Set string value. 222 * 223 * @param key The attribute key. 224 * @param value The string. 225 * @return Return success or not(true:success; false:failed). 226 */ 227 bool SetStringValue(AttributeKey key, const std::string &value); 228 229 /** 230 * @brief Set Attributes value. 231 * 232 * @param key The attribute key. 233 * @param value The attributes type value. 234 * @return Return success or not(true:success; false:failed). 235 */ 236 bool SetAttributesValue(AttributeKey key, const Attributes &value); 237 238 /** 239 * @brief Set vector<uint64_t> value. 240 * 241 * @param key The attribute key. 242 * @param value The vector<uint64_t> value. 243 * @return Return success or not(true:success; false:failed). 244 */ 245 bool SetUint64ArrayValue(AttributeKey key, const std::vector<uint64_t> &value); 246 247 /** 248 * @brief Set vector<uint32_t> value. 249 * 250 * @param key The attribute key. 251 * @param value The vector<uint32_t> value. 252 * @return Return success or not(true:success; false:failed). 253 */ 254 bool SetUint32ArrayValue(AttributeKey key, const std::vector<uint32_t> &value); 255 256 /** 257 * @brief Set vector<uint16_t> value. 258 * 259 * @param key The attribute key. 260 * @param value The vector<uint16_t> value. 261 * @return Return success or not(true:success; false:failed). 262 */ 263 bool SetUint16ArrayValue(AttributeKey key, const std::vector<uint16_t> &value); 264 265 /** 266 * @brief Set vector<uint8_t> value. 267 * 268 * @param key The attribute key. 269 * @param value The vector<uint8_t> value. 270 * @return Return success or not(true:success; false:failed). 271 */ 272 bool SetUint8ArrayValue(AttributeKey key, const std::vector<uint8_t> &value); 273 274 /** 275 * @brief Get bool value. 276 * 277 * @param key The attribute key. 278 * @param value Return bool value corresponding to key. 279 * @return Return success or not(true:success; false:failed). 280 */ 281 bool GetBoolValue(AttributeKey key, bool &value) const; 282 283 /** 284 * @brief Get uint64_t value. 285 * 286 * @param key The attribute key. 287 * @param value Return uint64_t value corresponding to key. 288 * @return Return success or not(true:success; false:failed). 289 */ 290 bool GetUint64Value(AttributeKey key, uint64_t &value) const; 291 292 /** 293 * @brief Get uint32_t value. 294 * 295 * @param key The attribute key. 296 * @param value Return uint32_t value corresponding to key. 297 * @return Return success or not(true:success; false:failed). 298 */ 299 bool GetUint32Value(AttributeKey key, uint32_t &value) const; 300 301 /** 302 * @brief Get uint16_t value. 303 * 304 * @param key The attribute key. 305 * @param value Return uint16_t value corresponding to key. 306 * @return Return success or not(true:success; false:failed). 307 */ 308 bool GetUint16Value(AttributeKey key, uint16_t &value) const; 309 310 /** 311 * @brief Get uint8_t value. 312 * 313 * @param key The attribute key. 314 * @param value Return uint8_t value corresponding to key. 315 * @return Return success or not(true:success; false:failed). 316 */ 317 bool GetUint8Value(AttributeKey key, uint8_t &value) const; 318 319 /** 320 * @brief Get int32_t value. 321 * 322 * @param key The attribute key. 323 * @param value Return int32_t value corresponding to key. 324 * @return Return success or not(true:success; false:failed). 325 */ 326 bool GetInt32Value(AttributeKey key, int32_t &value) const; 327 328 /** 329 * @brief Get string value. 330 * 331 * @param key The attribute key. 332 * @param value Return string corresponding to key. 333 * @return Return success or not(true:success; false:failed). 334 */ 335 bool GetStringValue(AttributeKey key, std::string &value) const; 336 337 /** 338 * @brief Get vector<uint64_t> value. 339 * 340 * @param key The attribute key. 341 * @param value Return vector<uint64_t> value corresponding to key. 342 * @return Return success or not(true:success; false:failed). 343 */ 344 bool GetUint64ArrayValue(AttributeKey key, std::vector<uint64_t> &value) const; 345 346 /** 347 * @brief Get vector<uint32_t> value. 348 * 349 * @param key The attribute key. 350 * @param value Return vector<uint32_t> value corresponding to key. 351 * @return Return success or not(true:success; false:failed). 352 */ 353 bool GetUint32ArrayValue(AttributeKey key, std::vector<uint32_t> &value) const; 354 355 /** 356 * @brief Get vector<uint16_t> value. 357 * 358 * @param key The attribute key. 359 * @param value Return vector<uint16_t> value corresponding to key. 360 * @return Return success or not(true:success; false:failed). 361 */ 362 bool GetUint16ArrayValue(AttributeKey key, std::vector<uint16_t> &value) const; 363 364 /** 365 * @brief Get vector<uint8_t> value. 366 * 367 * @param key The attribute key. 368 * @param value Return vector<uint8_t> value corresponding to key. 369 * @return Return success or not(true:success; false:failed). 370 */ 371 bool GetUint8ArrayValue(AttributeKey key, std::vector<uint8_t> &value) const; 372 373 /** 374 * @brief Get Attributes value. 375 * 376 * @param key The attribute key. 377 * @param value Return Attributes value corresponding to key. 378 * @return Return success or not(true:success; false:failed). 379 */ 380 bool GetAttributesValue(AttributeKey key, Attributes &value) const; 381 382 /** 383 * @brief Serialize the Attribute object. 384 * 385 * @return Return serialized Attribute object. 386 */ 387 std::vector<uint8_t> Serialize() const; 388 389 /** 390 * @brief Get all keys of Attribute. 391 * 392 * @return Return all keys of Attribute. 393 */ 394 std::vector<AttributeKey> GetKeys() const; 395 396 private: 397 class Impl; 398 std::unique_ptr<Impl> impl_; 399 }; 400 } // namespace UserAuth 401 } // namespace UserIam 402 } // namespace OHOS 403 404 #endif // IAM_ATTRIBUTES_H 405