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 #ifndef IAM_ATTRIBUTES_H 17 #define IAM_ATTRIBUTES_H 18 19 #include <memory> 20 #include <string> 21 #include <vector> 22 23 namespace OHOS { 24 namespace UserIam { 25 namespace UserAuth { 26 class Attributes final { 27 public: 28 enum AttributeKey : uint32_t { 29 ATTR_ROOT = 100000, 30 ATTR_RESULT_CODE = 100001, // int32_t 31 ATTR_SIGNATURE = 100004, // std::vector<uint8_t> 32 ATTR_IDENTIFY_MODE = 100005, // uint32_t 33 ATTR_TEMPLATE_ID = 100006, // uint64_t 34 ATTR_TEMPLATE_ID_LIST = 100007, // std::vector<uint64_t> 35 ATTR_ERROR_COUNT = 100008, // int32_t 36 ATTR_REMAIN_TIMES = 100009, // int32_t 37 ATTR_FREEZING_TIME = 100010, // int32_t 38 ATTR_SESSION_ID = 100014, // uint64_t 39 ATTR_SCHEDULE_VERSION = 100016, // uint32_t 40 ATTR_SCHEDULE_ID = 100020, // uint64_t 41 ATTR_PIN_SUB_TYPE = 100021, // int32_t 42 ATTR_SCHEDULE_MODE = 100022, // int32_t 43 ATTR_PROPERTY_MODE = 100023, // uint32_t 44 ATTR_AUTH_TYPE = 100024, // int32_t 45 ATTR_CREDENTIAL_ID = 100025, // uint64_t 46 ATTR_CALLER_UID = 100027, // uint64_t 47 ATTR_RESULT = 100028, // std::vector<uint8_t> 48 ATTR_CAPABILITY_LEVEL = 100029, // uint64_t 49 ATTR_ALGORITHM_INFO = 100030, // uint64_t 50 ATTR_TIME_STAMP = 100031, // uint64_t 51 ATTR_ROOT_SECRET = 100032, // std::vector<uint8_t> 52 ATTR_AUTH_TOKEN = 100033, // std::vector<uint8_t> 53 54 // private attrs 55 ATTR_USER_ID = 300000, // int32_t 56 ATTR_EXTRA_INFO, // std::vector<uint8_t> 57 ATTR_EXECUTOR_INDEX, // uint64_t 58 ATTR_EXECUTOR_SENSOR_HINT, // uint32_t 59 ATTR_EXECUTOR_MATCHER, // uint32_t 60 ATTR_ACCESS_TOKEN_ID, // uint32_t 61 }; 62 63 Attributes(); 64 65 explicit Attributes(const std::vector<uint8_t> &raw); 66 67 Attributes(const Attributes &other) = delete; 68 Attributes &operator=(const Attributes &other) = delete; 69 70 Attributes(Attributes &&other) noexcept; 71 Attributes &operator=(Attributes &&other) noexcept; 72 73 virtual ~Attributes(); 74 75 bool SetBoolValue(AttributeKey key, bool value); 76 bool SetUint64Value(AttributeKey key, uint64_t value); 77 bool SetUint32Value(AttributeKey key, uint32_t value); 78 bool SetUint16Value(AttributeKey key, uint16_t value); 79 bool SetUint8Value(AttributeKey key, uint8_t value); 80 bool SetInt32Value(AttributeKey key, int32_t value); 81 bool SetStringValue(AttributeKey key, const std::string &value); 82 bool SetAttributesValue(AttributeKey key, const Attributes &value); 83 bool SetUint64ArrayValue(AttributeKey key, const std::vector<uint64_t> &value); 84 bool SetUint32ArrayValue(AttributeKey key, const std::vector<uint32_t> &value); 85 bool SetUint16ArrayValue(AttributeKey key, const std::vector<uint16_t> &value); 86 bool SetUint8ArrayValue(AttributeKey key, const std::vector<uint8_t> &value); 87 88 bool GetBoolValue(AttributeKey key, bool &value) const; 89 bool GetUint64Value(AttributeKey key, uint64_t &value) const; 90 bool GetUint32Value(AttributeKey key, uint32_t &value) const; 91 bool GetUint16Value(AttributeKey key, uint16_t &value) const; 92 bool GetUint8Value(AttributeKey key, uint8_t &value) const; 93 bool GetInt32Value(AttributeKey key, int32_t &value) const; 94 bool GetStringValue(AttributeKey key, std::string &value) const; 95 bool GetUint64ArrayValue(AttributeKey key, std::vector<uint64_t> &value) const; 96 bool GetUint32ArrayValue(AttributeKey key, std::vector<uint32_t> &value) const; 97 bool GetUint16ArrayValue(AttributeKey key, std::vector<uint16_t> &value) const; 98 bool GetUint8ArrayValue(AttributeKey key, std::vector<uint8_t> &value) const; 99 bool GetAttributesValue(AttributeKey key, Attributes &value) const; 100 std::vector<uint8_t> Serialize() const; 101 std::vector<AttributeKey> GetKeys() const; 102 103 private: 104 class Impl; 105 std::unique_ptr<Impl> impl_; 106 }; 107 } // namespace UserAuth 108 } // namespace UserIam 109 } // namespace OHOS 110 111 #endif // IAM_ATTRIBUTES_H 112