Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDarshan Sen <raisinten@gmail.com>2022-04-11 07:07:43 +0300
committerGitHub <noreply@github.com>2022-04-11 07:07:43 +0300
commit0c57a37dd0bdd3fabd2e7e8b12a5dbd695ae3509 (patch)
treea19f9ddd91d75e6f17db430a62e6800293135117 /src
parent951dbc045aebbe1f7eff12cedabce1179544dc75 (diff)
src,crypto: remove uses of AllocatedBuffer from crypto_tls.cc
Refs: https://github.com/nodejs/node/pull/39941 Signed-off-by: Darshan Sen <raisinten@gmail.com> PR-URL: https://github.com/nodejs/node/pull/42589 Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/crypto/crypto_tls.cc63
1 files changed, 49 insertions, 14 deletions
diff --git a/src/crypto/crypto_tls.cc b/src/crypto/crypto_tls.cc
index 72b49e05f0c..2d0f0c4e735 100644
--- a/src/crypto/crypto_tls.cc
+++ b/src/crypto/crypto_tls.cc
@@ -25,7 +25,6 @@
#include "crypto/crypto_util.h"
#include "crypto/crypto_bio.h"
#include "crypto/crypto_clienthello-inl.h"
-#include "allocated_buffer-inl.h"
#include "async_wrap-inl.h"
#include "debug_utils-inl.h"
#include "memory_tracker-inl.h"
@@ -1611,9 +1610,19 @@ void TLSWrap::GetFinished(const FunctionCallbackInfo<Value>& args) {
if (len == 0)
return;
- AllocatedBuffer buf = AllocatedBuffer::AllocateManaged(env, len);
- CHECK_EQ(len, SSL_get_finished(w->ssl_.get(), buf.data(), len));
- args.GetReturnValue().Set(buf.ToBuffer().FromMaybe(Local<Value>()));
+ std::unique_ptr<BackingStore> bs;
+ {
+ NoArrayBufferZeroFillScope no_zero_fill_scope(env->isolate_data());
+ bs = ArrayBuffer::NewBackingStore(env->isolate(), len);
+ }
+
+ CHECK_EQ(bs->ByteLength(),
+ SSL_get_finished(w->ssl_.get(), bs->Data(), bs->ByteLength()));
+
+ Local<ArrayBuffer> ab = ArrayBuffer::New(env->isolate(), std::move(bs));
+ Local<Value> buffer;
+ if (!Buffer::New(env, ab, 0, ab->ByteLength()).ToLocal(&buffer)) return;
+ args.GetReturnValue().Set(buffer);
}
void TLSWrap::GetPeerFinished(const FunctionCallbackInfo<Value>& args) {
@@ -1632,9 +1641,19 @@ void TLSWrap::GetPeerFinished(const FunctionCallbackInfo<Value>& args) {
if (len == 0)
return;
- AllocatedBuffer buf = AllocatedBuffer::AllocateManaged(env, len);
- CHECK_EQ(len, SSL_get_peer_finished(w->ssl_.get(), buf.data(), len));
- args.GetReturnValue().Set(buf.ToBuffer().FromMaybe(Local<Value>()));
+ std::unique_ptr<BackingStore> bs;
+ {
+ NoArrayBufferZeroFillScope no_zero_fill_scope(env->isolate_data());
+ bs = ArrayBuffer::NewBackingStore(env->isolate(), len);
+ }
+
+ CHECK_EQ(bs->ByteLength(),
+ SSL_get_peer_finished(w->ssl_.get(), bs->Data(), bs->ByteLength()));
+
+ Local<ArrayBuffer> ab = ArrayBuffer::New(env->isolate(), std::move(bs));
+ Local<Value> buffer;
+ if (!Buffer::New(env, ab, 0, ab->ByteLength()).ToLocal(&buffer)) return;
+ args.GetReturnValue().Set(buffer);
}
void TLSWrap::GetSession(const FunctionCallbackInfo<Value>& args) {
@@ -1651,10 +1670,19 @@ void TLSWrap::GetSession(const FunctionCallbackInfo<Value>& args) {
if (slen <= 0)
return; // Invalid or malformed session.
- AllocatedBuffer sbuf = AllocatedBuffer::AllocateManaged(env, slen);
- unsigned char* p = reinterpret_cast<unsigned char*>(sbuf.data());
+ std::unique_ptr<BackingStore> bs;
+ {
+ NoArrayBufferZeroFillScope no_zero_fill_scope(env->isolate_data());
+ bs = ArrayBuffer::NewBackingStore(env->isolate(), slen);
+ }
+
+ unsigned char* p = static_cast<unsigned char*>(bs->Data());
CHECK_LT(0, i2d_SSL_SESSION(sess, &p));
- args.GetReturnValue().Set(sbuf.ToBuffer().FromMaybe(Local<Value>()));
+
+ Local<ArrayBuffer> ab = ArrayBuffer::New(env->isolate(), std::move(bs));
+ Local<Value> buffer;
+ if (!Buffer::New(env, ab, 0, ab->ByteLength()).ToLocal(&buffer)) return;
+ args.GetReturnValue().Set(buffer);
}
void TLSWrap::SetSession(const FunctionCallbackInfo<Value>& args) {
@@ -1825,7 +1853,11 @@ void TLSWrap::ExportKeyingMaterial(const FunctionCallbackInfo<Value>& args) {
uint32_t olen = args[0].As<Uint32>()->Value();
Utf8Value label(env->isolate(), args[1]);
- AllocatedBuffer out = AllocatedBuffer::AllocateManaged(env, olen);
+ std::unique_ptr<BackingStore> bs;
+ {
+ NoArrayBufferZeroFillScope no_zero_fill_scope(env->isolate_data());
+ bs = ArrayBuffer::NewBackingStore(env->isolate(), olen);
+ }
ByteSource context;
bool use_context = !args[2]->IsUndefined();
@@ -1834,11 +1866,11 @@ void TLSWrap::ExportKeyingMaterial(const FunctionCallbackInfo<Value>& args) {
if (SSL_export_keying_material(
w->ssl_.get(),
- reinterpret_cast<unsigned char*>(out.data()),
+ static_cast<unsigned char*>(bs->Data()),
olen,
*label,
label.length(),
- reinterpret_cast<const unsigned char*>(context.get()),
+ context.data<unsigned char>(),
context.size(),
use_context) != 1) {
return ThrowCryptoError(
@@ -1847,7 +1879,10 @@ void TLSWrap::ExportKeyingMaterial(const FunctionCallbackInfo<Value>& args) {
"SSL_export_keying_material");
}
- args.GetReturnValue().Set(out.ToBuffer().FromMaybe(Local<Value>()));
+ Local<ArrayBuffer> ab = ArrayBuffer::New(env->isolate(), std::move(bs));
+ Local<Value> buffer;
+ if (!Buffer::New(env, ab, 0, ab->ByteLength()).ToLocal(&buffer)) return;
+ args.GetReturnValue().Set(buffer);
}
void TLSWrap::EndParser(const FunctionCallbackInfo<Value>& args) {