From 0847bc37882c6aef1dc29c30ae051edc9bb09698 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] crypto: simplify exportKeyingMaterial PR-URL: https://github.com/nodejs/node/pull/31922 Reviewed-By: Anna Henningsen Reviewed-By: Colin Ihrig Reviewed-By: James M Snell Reviewed-By: David Carlier --- 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 edacfb03266722..932a95e4a35727 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -2233,14 +2233,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()), @@ -2248,9 +2244,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"); }