1 /* 2 * Copyright (c) 2022-2023 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_CONTEXT_FACTORY_H 17 #define IAM_CONTEXT_FACTORY_H 18 19 #include <cstdint> 20 #include <map> 21 #include <memory> 22 #include <string> 23 24 #include "singleton.h" 25 #include "context.h" 26 #include "context_callback.h" 27 28 namespace OHOS { 29 namespace UserIam { 30 namespace UserAuth { 31 class ContextFactory : public DelayedSingleton<ContextFactory> { 32 public: 33 struct AuthContextPara { 34 int32_t userId {0}; 35 AuthType authType {ALL}; 36 AuthTrustLevel atl {ATL1}; 37 uint32_t tokenId {0}; 38 std::vector<uint8_t> challenge; 39 bool endAfterFirstFail; 40 }; 41 42 struct AuthWidgetContextPara { 43 struct AuthProfile { 44 int32_t pinSubType {0}; 45 std::string sensorInfo {""}; 46 int32_t remainTimes {0}; 47 int32_t freezingTime {0}; 48 }; 49 50 int32_t userId {0}; 51 uint32_t tokenId {0}; 52 int32_t callingUid {0}; 53 std::vector<uint8_t> challenge {}; 54 std::vector<AuthType> authTypeList {}; 55 AuthTrustLevel atl {ATL1}; 56 WidgetParam widgetParam {}; 57 std::map<AuthType, AuthProfile> authProfileMap {}; 58 }; 59 60 struct IdentifyContextPara { 61 AuthType authType {ALL}; 62 uint32_t tokenId {0}; 63 std::vector<uint8_t> challenge; 64 }; 65 66 struct EnrollContextPara { 67 int32_t userId {0}; 68 AuthType authType {ALL}; 69 PinSubType pinType {PIN_SIX}; 70 bool isUpdate {false}; 71 uint32_t tokenId {0}; 72 std::vector<uint8_t> token; 73 }; 74 static std::shared_ptr<Context> CreateSimpleAuthContext(const AuthContextPara ¶, 75 const std::shared_ptr<ContextCallback> &callback); 76 static std::shared_ptr<Context> CreateIdentifyContext(const IdentifyContextPara ¶, 77 const std::shared_ptr<ContextCallback> &callback); 78 static std::shared_ptr<Context> CreateEnrollContext(const EnrollContextPara ¶, 79 const std::shared_ptr<ContextCallback> &callback); 80 static std::shared_ptr<Context> CreateWidgetAuthContext(std::shared_ptr<ContextCallback> callback); 81 static std::shared_ptr<Context> CreateWidgetContext(const AuthWidgetContextPara ¶, 82 std::shared_ptr<ContextCallback> callback); 83 }; 84 } // namespace UserAuth 85 } // namespace UserIam 86 } // namespace OHOS 87 #endif // IAM_CONTEXT_FACTORY_H