From 62e211d919c8bebf96a1f69a214b444ff0a63894 Mon Sep 17 00:00:00 2001 From: Darshan Sen Date: Sun, 24 Apr 2022 20:07:15 +0530 Subject: [PATCH] src,crypto: remove uses of AllocatedBuffer from crypto_rsa.cc Refs: https://github.com/nodejs/node/pull/39941 Signed-off-by: Darshan Sen --- src/crypto/crypto_rsa.cc | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/crypto/crypto_rsa.cc b/src/crypto/crypto_rsa.cc index ae4550e9fde812..62d54db8a3dde3 100644 --- a/src/crypto/crypto_rsa.cc +++ b/src/crypto/crypto_rsa.cc @@ -15,6 +15,8 @@ namespace node { +using v8::ArrayBuffer; +using v8::BackingStore; using v8::FunctionCallbackInfo; using v8::Int32; using v8::Just; @@ -555,17 +557,21 @@ Maybe GetRsaKeyDetail( return Nothing(); } - int len = BN_num_bytes(e); - AllocatedBuffer public_exponent = AllocatedBuffer::AllocateManaged(env, len); - unsigned char* data = - reinterpret_cast(public_exponent.data()); - CHECK_EQ(BN_bn2binpad(e, data, len), len); + std::unique_ptr public_exponent; + { + NoArrayBufferZeroFillScope no_zero_fill_scope(env->isolate_data()); + public_exponent = + ArrayBuffer::NewBackingStore(env->isolate(), BN_num_bytes(e)); + } + CHECK_EQ(BN_bn2binpad(e, + static_cast(public_exponent->Data()), + public_exponent->ByteLength()), + static_cast(public_exponent->ByteLength())); if (target - ->Set( - env->context(), - env->public_exponent_string(), - public_exponent.ToArrayBuffer()) + ->Set(env->context(), + env->public_exponent_string(), + ArrayBuffer::New(env->isolate(), std::move(public_exponent))) .IsNothing()) { return Nothing(); }