Skip to content

Commit 8cfc18e

Browse files
RaisinTenRafaelGSS
authored andcommitted
src,crypto: remove uses of AllocatedBuffer from crypto_rsa.cc
Refs: #39941 Signed-off-by: Darshan Sen <raisinten@gmail.com> PR-URL: #42852 Reviewed-By: Anna Henningsen <anna@addaleax.net>
1 parent 19c060f commit 8cfc18e

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

src/crypto/crypto_rsa.cc

+15-9
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
namespace node {
1717

18+
using v8::ArrayBuffer;
19+
using v8::BackingStore;
1820
using v8::FunctionCallbackInfo;
1921
using v8::Int32;
2022
using v8::Just;
@@ -555,17 +557,21 @@ Maybe<bool> GetRsaKeyDetail(
555557
return Nothing<bool>();
556558
}
557559

558-
int len = BN_num_bytes(e);
559-
AllocatedBuffer public_exponent = AllocatedBuffer::AllocateManaged(env, len);
560-
unsigned char* data =
561-
reinterpret_cast<unsigned char*>(public_exponent.data());
562-
CHECK_EQ(BN_bn2binpad(e, data, len), len);
560+
std::unique_ptr<BackingStore> public_exponent;
561+
{
562+
NoArrayBufferZeroFillScope no_zero_fill_scope(env->isolate_data());
563+
public_exponent =
564+
ArrayBuffer::NewBackingStore(env->isolate(), BN_num_bytes(e));
565+
}
566+
CHECK_EQ(BN_bn2binpad(e,
567+
static_cast<unsigned char*>(public_exponent->Data()),
568+
public_exponent->ByteLength()),
569+
static_cast<int>(public_exponent->ByteLength()));
563570

564571
if (target
565-
->Set(
566-
env->context(),
567-
env->public_exponent_string(),
568-
public_exponent.ToArrayBuffer())
572+
->Set(env->context(),
573+
env->public_exponent_string(),
574+
ArrayBuffer::New(env->isolate(), std::move(public_exponent)))
569575
.IsNothing()) {
570576
return Nothing<bool>();
571577
}

0 commit comments

Comments
 (0)