Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src,crypto: remove uses of AllocatedBuffer from crypto_rsa.cc #42852

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions src/crypto/crypto_rsa.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

namespace node {

using v8::ArrayBuffer;
using v8::BackingStore;
using v8::FunctionCallbackInfo;
using v8::Int32;
using v8::Just;
Expand Down Expand Up @@ -555,17 +557,21 @@ Maybe<bool> GetRsaKeyDetail(
return Nothing<bool>();
}

int len = BN_num_bytes(e);
AllocatedBuffer public_exponent = AllocatedBuffer::AllocateManaged(env, len);
unsigned char* data =
reinterpret_cast<unsigned char*>(public_exponent.data());
CHECK_EQ(BN_bn2binpad(e, data, len), len);
std::unique_ptr<BackingStore> 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<unsigned char*>(public_exponent->Data()),
public_exponent->ByteLength()),
static_cast<int>(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<bool>();
}
Expand Down