From 7d46e3efc05bec08cb5f729b873bbac7a109a3b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Nie=C3=9Fen?= Date: Sun, 23 Feb 2020 10:58:36 -0400 Subject: [PATCH 1/2] crypto: simplify exportKeyingMaterial --- src/node_crypto.cc | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/node_crypto.cc b/src/node_crypto.cc index e129c7f3f595ae..ff5d90440a5b74 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -2789,14 +2789,10 @@ void SSLWrap::ExportKeyingMaterial( AllocatedBuffer out = env->AllocateManaged(olen); - ByteSource key; - - int useContext = 0; - if (!args[2]->IsNull() && Buffer::HasInstance(args[2])) { - key = ByteSource::FromBuffer(args[2]); - - useContext = 1; - } + ByteSource context; + bool use_context = !args[2]->IsUndefined(); + if (use_context) + context = ByteSource::FromBuffer(args[2]); if (SSL_export_keying_material(w->ssl_.get(), reinterpret_cast(out.data()), @@ -2804,9 +2800,9 @@ void SSLWrap::ExportKeyingMaterial( *label, label.length(), reinterpret_cast( - key.get()), - key.size(), - useContext) != 1) { + context.get()), + context.size(), + use_context) != 1) { return ThrowCryptoError(env, ERR_get_error(), "SSL_export_keying_material"); } From 8a7076881a5a02bb292813d402fcf3ef9418f57d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Nie=C3=9Fen?= Date: Mon, 24 Feb 2020 08:36:53 -0400 Subject: [PATCH 2/2] Update src/node_crypto.cc Co-Authored-By: Anna Henningsen --- src/node_crypto.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/node_crypto.cc b/src/node_crypto.cc index ff5d90440a5b74..2c3fd3c802fa09 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -2800,7 +2800,7 @@ void SSLWrap::ExportKeyingMaterial( *label, label.length(), reinterpret_cast( - context.get()), + context.get()), context.size(), use_context) != 1) { return ThrowCryptoError(env, ERR_get_error(), "SSL_export_keying_material");