build: export more OpenSSL symbols on Windows

PR-URL: https://github.com/nodejs/node/pull/45486
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
This commit is contained in:
Mohamed Akram 2023-01-31 11:19:01 +04:00 committed by GitHub
parent 938341ac61
commit 3abd559c6a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 3 deletions

View File

@ -826,7 +826,8 @@
'-CAES,BF,BIO,DES,DH,DSA,EC,ECDH,ECDSA,ENGINE,EVP,HMAC,MD4,MD5,'
'PSK,RC2,RC4,RSA,SHA,SHA0,SHA1,SHA256,SHA512,SOCK,STDIO,TLSEXT,'
'UI,FP_API,TLS1_METHOD,TLS1_1_METHOD,TLS1_2_METHOD,SCRYPT,OCSP,'
'NEXTPROTONEG,RMD160,CAST,DEPRECATEDIN_1_1_0,DEPRECATEDIN_1_2_0',
'NEXTPROTONEG,RMD160,CAST,DEPRECATEDIN_1_1_0,DEPRECATEDIN_1_2_0,'
'DEPRECATEDIN_3_0',
# Defines.
'-DWIN32',
# Symbols to filter from the export list.

View File

@ -1,7 +1,8 @@
#include <assert.h>
#include <node.h>
#include <openssl/md5.h>
#include <openssl/rand.h>
#include <openssl/ssl.h>
#include <node.h>
#include <assert.h>
namespace {
@ -19,6 +20,21 @@ inline void RandomBytes(const v8::FunctionCallbackInfo<v8::Value>& info) {
info.GetReturnValue().Set(rval > 0);
}
inline void Hash(const v8::FunctionCallbackInfo<v8::Value>& info) {
assert(info[0]->IsArrayBufferView());
auto view = info[0].As<v8::ArrayBufferView>();
auto byte_offset = view->ByteOffset();
auto len = view->ByteLength();
assert(view->HasBuffer());
auto buffer = view->Buffer();
auto contents = buffer->GetBackingStore();
auto data = static_cast<unsigned char*>(contents->Data()) + byte_offset;
unsigned char md[MD5_DIGEST_LENGTH];
MD5_CTX c;
auto rval = MD5_Init(&c) && MD5_Update(&c, data, len) && MD5_Final(md, &c);
info.GetReturnValue().Set(rval > 0);
}
inline void Initialize(v8::Local<v8::Object> exports,
v8::Local<v8::Value> module,
v8::Local<v8::Context> context) {
@ -32,6 +48,12 @@ inline void Initialize(v8::Local<v8::Object> exports,
const SSL_METHOD* method = TLSv1_2_server_method();
assert(method != nullptr);
key = v8::String::NewFromUtf8(isolate, "hash").ToLocalChecked();
value = v8::FunctionTemplate::New(isolate, Hash)
->GetFunction(context)
.ToLocalChecked();
assert(exports->Set(context, key, value).IsJust());
}
} // anonymous namespace

View File

@ -9,3 +9,4 @@ const binding = require(`./build/${common.buildType}/binding`);
const bytes = new Uint8Array(1024);
assert(binding.randomBytes(bytes));
assert(bytes.reduce((v, a) => v + a) > 0);
assert(binding.hash(bytes));