Skip to content

Commit

Permalink
crypto: simplify exportKeyingMaterial
Browse files Browse the repository at this point in the history
PR-URL: nodejs#31922
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: David Carlier <devnexen@gmail.com>
  • Loading branch information
tniessen authored and targos committed Apr 25, 2020
1 parent fcbb571 commit cfaa156
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions src/node_crypto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2233,24 +2233,20 @@ void SSLWrap<Base>::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<unsigned char*>(out.data()),
olen,
*label,
label.length(),
reinterpret_cast<const unsigned char*>(
key.get()),
key.size(),
useContext) != 1) {
context.get()),
context.size(),
use_context) != 1) {
return ThrowCryptoError(env, ERR_get_error(), "SSL_export_keying_material");
}

Expand Down

0 comments on commit cfaa156

Please sign in to comment.