• 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 <ani.h>
17 #include "ani_signature.h"
18 #include "bind_function.h"
19 #include "hash_ani.h"
20 #include "hashstream_ani.h"
21 
22 using namespace OHOS::FileManagement::ModuleFileIO::ANI;
23 using namespace OHOS::FileManagement::ModuleFileIO::ANI::AniSignature;
24 
BindStaticMethods(ani_env * env)25 static ani_status BindStaticMethods(ani_env *env)
26 {
27     auto classDesc = Impl::HashImpl::classDesc.c_str();
28     std::array methods = {
29         ani_native_function { "hashSync", nullptr, reinterpret_cast<void *>(HashAni::HashSync) },
30     };
31     return BindClass(env, classDesc, methods);
32 }
33 
ANI_Constructor(ani_vm * vm,uint32_t * result)34 ANI_EXPORT ani_status ANI_Constructor(ani_vm *vm, uint32_t *result)
35 {
36     if (vm == nullptr) {
37         HILOGE("Invalid parameter vm");
38         return ANI_INVALID_ARGS;
39     }
40 
41     if (result == nullptr) {
42         HILOGE("Invalid parameter result");
43         return ANI_INVALID_ARGS;
44     }
45 
46     ani_env *env;
47     ani_status status = vm->GetEnv(ANI_VERSION_1, &env);
48     if (status != ANI_OK) {
49         HILOGE("Invalid ani version!");
50         return ANI_INVALID_VERSION;
51     }
52 
53     status = BindStaticMethods(env);
54     if (status != ANI_OK) {
55         HILOGE("Cannot bind native static methods for hash!");
56         return status;
57     };
58 
59     *result = ANI_VERSION_1;
60     return ANI_OK;
61 }
62