• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "useriam_common.h"
17 
18 #include <sys/stat.h>
19 #include <unistd.h>
20 
21 #include "pool.h"
22 #include "idm_database.h"
23 #include "coauth.h"
24 #include "context_manager.h"
25 #include "adaptor_log.h"
26 #include "ed25519_key.h"
27 
28 namespace OHOS {
29 namespace UserIam {
30 namespace Common {
31 static bool g_isInitUserIAM = false;
32 
Init()33 int32_t Init()
34 {
35     if (InitUserAuthContextList() != RESULT_SUCCESS) {
36         LOG_ERROR("init context list failed");
37         goto FAIL;
38     }
39 
40     if (InitResourcePool() != RESULT_SUCCESS) {
41         LOG_ERROR("init resource pool failed");
42         goto FAIL;
43     }
44     if (InitUserInfoList() != RESULT_SUCCESS) {
45         LOG_ERROR("init user info failed");
46         goto FAIL;
47     }
48     if (InitCoAuth() != RESULT_SUCCESS) {
49         LOG_ERROR("init user auth failed");
50         goto FAIL;
51     }
52     if (GenerateKeyPair() != RESULT_SUCCESS) {
53         LOG_ERROR("init ed25519 key failed");
54         goto FAIL;
55     }
56     LOG_INFO("init success");
57     g_isInitUserIAM = true;
58     return RESULT_SUCCESS;
59 
60 FAIL:
61     Close();
62     return RESULT_UNKNOWN;
63 }
64 
Close()65 int32_t Close()
66 {
67     DestoryUserAuthContextList();
68     DestoryCoAuth();
69     DestroyUserInfoList();
70     DestroyResourcePool();
71     DestoryEd25519KeyPair();
72     g_isInitUserIAM = false;
73     return RESULT_SUCCESS;
74 }
75 
IsIAMInited()76 bool IsIAMInited()
77 {
78     return g_isInitUserIAM;
79 }
80 } // Common
81 } // UserIam
82 } // OHOS