• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 #include "keymanager_n_exporter.h"
16 
17 #include "n_error.h"
18 #include "n_func_arg.h"
19 #include "storage_manager_connect.h"
20 #include "storage_service_errno.h"
21 
22 using namespace OHOS::StorageManager;
23 using namespace OHOS::FileManagement::LibN;
24 
25 namespace OHOS {
26 namespace StorageManager {
27 
DeactivateUserKey(napi_env env,napi_callback_info info)28 napi_value DeactivateUserKey(napi_env env, napi_callback_info info)
29 {
30     if (!IsSystemApp()) {
31         NError(E_PERMISSION_SYS).ThrowErr(env);
32         return nullptr;
33     }
34     NFuncArg funcArg(env, info);
35     if (!funcArg.InitArgs((int)NARG_CNT::ZERO, (int)NARG_CNT::ONE)) {
36         NError(E_PARAMS).ThrowErr(env);
37         return nullptr;
38     }
39     bool succ = false;
40     uint32_t userId;
41     std::tie(succ, userId) = NVal(env, funcArg[(int)NARG_POS::FIRST]).ToUint32();
42     if (!succ) {
43         NError(E_PARAMS).ThrowErr(env);
44         return nullptr;
45     }
46     auto err = DelayedSingleton<StorageManagerConnect>::GetInstance()->DeactivateUserKey(userId);
47     if (err != E_OK) {
48         NError(Convert2JsErrNum(err)).ThrowErr(env);
49         return nullptr;
50     }
51     return NVal::CreateUndefined(env).val_;
52 }
53 } // namespace StorageManager
54 } // namespace OHOS