diff --git a/node.gyp b/node.gyp index cec24aed034362..0b5c3ff5ba92b9 100644 --- a/node.gyp +++ b/node.gyp @@ -900,7 +900,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. diff --git a/test/addons/openssl-binding/binding.cc b/test/addons/openssl-binding/binding.cc index 79472dd7f25272..06402022f4da66 100644 --- a/test/addons/openssl-binding/binding.cc +++ b/test/addons/openssl-binding/binding.cc @@ -1,7 +1,8 @@ +#include +#include +#include #include #include -#include -#include namespace { @@ -19,6 +20,21 @@ inline void RandomBytes(const v8::FunctionCallbackInfo& info) { info.GetReturnValue().Set(rval > 0); } +inline void Hash(const v8::FunctionCallbackInfo& info) { + assert(info[0]->IsArrayBufferView()); + auto view = info[0].As(); + auto byte_offset = view->ByteOffset(); + auto len = view->ByteLength(); + assert(view->HasBuffer()); + auto buffer = view->Buffer(); + auto contents = buffer->GetBackingStore(); + auto data = static_cast(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 exports, v8::Local module, v8::Local context) { @@ -32,6 +48,12 @@ inline void Initialize(v8::Local 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 diff --git a/test/addons/openssl-binding/test.js b/test/addons/openssl-binding/test.js index 1e6c57ffd1e081..669256d86b909a 100644 --- a/test/addons/openssl-binding/test.js +++ b/test/addons/openssl-binding/test.js @@ -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));