• 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 
57     LOG_INFO("init success");
58     g_isInitUserIAM = true;
59     return RESULT_SUCCESS;
60 
61 FAIL:
62     Close();
63     return RESULT_UNKNOWN;
64 }
65 
Close()66 int32_t Close()
67 {
68     DestoryUserAuthContextList();
69     DestoryCoAuth();
70     DestroyUserInfoList();
71     DestroyResourcePool();
72     DestoryEd25519KeyPair();
73     g_isInitUserIAM = false;
74     return RESULT_SUCCESS;
75 }
76 
IsIAMInited()77 bool IsIAMInited()
78 {
79     return g_isInitUserIAM;
80 }
81 } // Common
82 } // UserIam
83 } // OHOS