• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 "asset_napi_context.h"
17 
18 #include "asset_system_api.h"
19 
20 namespace OHOS {
21 namespace Security {
22 namespace Asset {
23 namespace {
FreeAssetAttrs(std::vector<AssetAttr> & attrs)24 void FreeAssetAttrs(std::vector<AssetAttr> &attrs)
25 {
26     for (auto attr : attrs) {
27         if ((attr.tag & SEC_ASSET_TAG_TYPE_MASK) == SEC_ASSET_TYPE_BYTES) {
28             AssetFreeBlob(&attr.value.blob);
29         }
30     }
31     attrs.clear();
32 }
33 } // anonymous namespace
34 
~BaseContext()35 BaseContext::~BaseContext()
36 {
37     if (work != nullptr && env != nullptr) {
38         napi_delete_async_work(env, work);
39         work = nullptr;
40         env = nullptr;
41     }
42 
43     FreeAssetAttrs(attrs);
44 }
45 
~PreQueryContext()46 PreQueryContext::~PreQueryContext()
47 {
48     AssetFreeBlob(&challenge);
49 }
50 
~QueryContext()51 QueryContext::~QueryContext()
52 {
53     AssetFreeResultSet(&resultSet);
54 }
55 
~UpdateContext()56 UpdateContext::~UpdateContext()
57 {
58     FreeAssetAttrs(updateAttrs);
59 }
60 
61 } // Asset
62 } // Security
63 } // OHOS
64