11cb0ef41Sopenharmony_ci#include <assert.h> 21cb0ef41Sopenharmony_ci#include <node.h> 31cb0ef41Sopenharmony_ci 41cb0ef41Sopenharmony_ci#include <openssl/opensslv.h> 51cb0ef41Sopenharmony_ci#if OPENSSL_VERSION_MAJOR >= 3 61cb0ef41Sopenharmony_ci#include <openssl/provider.h> 71cb0ef41Sopenharmony_ci#endif 81cb0ef41Sopenharmony_ci 91cb0ef41Sopenharmony_cinamespace { 101cb0ef41Sopenharmony_ci 111cb0ef41Sopenharmony_ciusing v8::Array; 121cb0ef41Sopenharmony_ciusing v8::Context; 131cb0ef41Sopenharmony_ciusing v8::FunctionCallbackInfo; 141cb0ef41Sopenharmony_ciusing v8::Isolate; 151cb0ef41Sopenharmony_ciusing v8::Local; 161cb0ef41Sopenharmony_ciusing v8::Object; 171cb0ef41Sopenharmony_ciusing v8::String; 181cb0ef41Sopenharmony_ciusing v8::Value; 191cb0ef41Sopenharmony_ci 201cb0ef41Sopenharmony_ci#if OPENSSL_VERSION_MAJOR >= 3 211cb0ef41Sopenharmony_ciint collectProviders(OSSL_PROVIDER* provider, void* cbdata) { 221cb0ef41Sopenharmony_ci static_cast<std::vector<OSSL_PROVIDER*>*>(cbdata)->push_back(provider); 231cb0ef41Sopenharmony_ci return 1; 241cb0ef41Sopenharmony_ci} 251cb0ef41Sopenharmony_ci#endif 261cb0ef41Sopenharmony_ci 271cb0ef41Sopenharmony_ciinline void GetProviders(const FunctionCallbackInfo<Value>& args) { 281cb0ef41Sopenharmony_ci Isolate* isolate = args.GetIsolate(); 291cb0ef41Sopenharmony_ci std::vector<Local<Value>> arr = {}; 301cb0ef41Sopenharmony_ci#if OPENSSL_VERSION_MAJOR >= 3 311cb0ef41Sopenharmony_ci std::vector<OSSL_PROVIDER*> providers; 321cb0ef41Sopenharmony_ci OSSL_PROVIDER_do_all(nullptr, &collectProviders, &providers); 331cb0ef41Sopenharmony_ci for (auto provider : providers) { 341cb0ef41Sopenharmony_ci arr.push_back( 351cb0ef41Sopenharmony_ci String::NewFromUtf8(isolate, OSSL_PROVIDER_get0_name(provider)) 361cb0ef41Sopenharmony_ci .ToLocalChecked()); 371cb0ef41Sopenharmony_ci } 381cb0ef41Sopenharmony_ci#endif 391cb0ef41Sopenharmony_ci args.GetReturnValue().Set(Array::New(isolate, arr.data(), arr.size())); 401cb0ef41Sopenharmony_ci} 411cb0ef41Sopenharmony_ci 421cb0ef41Sopenharmony_ciinline void Initialize(Local<Object> exports, 431cb0ef41Sopenharmony_ci Local<Value> module, 441cb0ef41Sopenharmony_ci Local<Context> context) { 451cb0ef41Sopenharmony_ci NODE_SET_METHOD(exports, "getProviders", GetProviders); 461cb0ef41Sopenharmony_ci} 471cb0ef41Sopenharmony_ci 481cb0ef41Sopenharmony_ci} // anonymous namespace 491cb0ef41Sopenharmony_ci 501cb0ef41Sopenharmony_ciNODE_MODULE_CONTEXT_AWARE(NODE_GYP_MODULE_NAME, Initialize) 51