From b4378aa38a7971b4da35210f8ced8961fdf3bf41 Mon Sep 17 00:00:00 2001 From: James M Snell Date: Thu, 7 Jan 2021 16:27:29 -0800 Subject: [PATCH] crypto: fixup bug in keygen error handling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: James M Snell PR-URL: https://github.com/nodejs/node/pull/36779 Refs: https://github.com/nodejs/node/pull/36729 Reviewed-By: Tobias Nießen --- lib/internal/crypto/keygen.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/internal/crypto/keygen.js b/lib/internal/crypto/keygen.js index 2b0d58afd663fc..56f06f7a79fe2a 100644 --- a/lib/internal/crypto/keygen.js +++ b/lib/internal/crypto/keygen.js @@ -94,13 +94,15 @@ function generateKeyPairSync(type, options) { } function handleError(ret) { - if (ret === undefined) + if (ret == null) return; // async - const [err, [publicKey, privateKey]] = ret; + const [err, keys] = ret; if (err !== undefined) throw err; + const [publicKey, privateKey] = keys; + // If no encoding was chosen, return key objects instead. return { publicKey: wrapKey(publicKey, PublicKeyObject),