From df08160857b8856ada8fc34a965df48f347101e1 Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Tue, 24 Apr 2018 08:45:35 +0200 Subject: [PATCH 1/3] crypto: simplify diffiehellman getFormat function This commit aims to simplify the getFormat function in diffiehellman.js. --- lib/internal/crypto/diffiehellman.js | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/lib/internal/crypto/diffiehellman.js b/lib/internal/crypto/diffiehellman.js index 329add6d4d7cd5..dbf17e97a159d2 100644 --- a/lib/internal/crypto/diffiehellman.js +++ b/lib/internal/crypto/diffiehellman.js @@ -219,21 +219,16 @@ function encode(buffer, encoding) { } function getFormat(format) { - let f; if (format) { if (format === 'compressed') - f = POINT_CONVERSION_COMPRESSED; + return POINT_CONVERSION_COMPRESSED; else if (format === 'hybrid') - f = POINT_CONVERSION_HYBRID; + return POINT_CONVERSION_HYBRID; // Default - else if (format === 'uncompressed') - f = POINT_CONVERSION_UNCOMPRESSED; - else + else if (format !== 'uncompressed') throw new ERR_CRYPTO_ECDH_INVALID_FORMAT(format); - } else { - f = POINT_CONVERSION_UNCOMPRESSED; } - return f; + return POINT_CONVERSION_UNCOMPRESSED; } module.exports = { From 61fa45edc3456cc5f48729e2a6f4580e1d4f87d1 Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Tue, 24 Apr 2018 11:43:57 +0200 Subject: [PATCH 2/3] squash: remove default comment --- lib/internal/crypto/diffiehellman.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/internal/crypto/diffiehellman.js b/lib/internal/crypto/diffiehellman.js index dbf17e97a159d2..37858bfb2c3bcd 100644 --- a/lib/internal/crypto/diffiehellman.js +++ b/lib/internal/crypto/diffiehellman.js @@ -224,7 +224,6 @@ function getFormat(format) { return POINT_CONVERSION_COMPRESSED; else if (format === 'hybrid') return POINT_CONVERSION_HYBRID; - // Default else if (format !== 'uncompressed') throw new ERR_CRYPTO_ECDH_INVALID_FORMAT(format); } From 071d70944aa9194c2cd4568a5daff2364afc594f Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Tue, 24 Apr 2018 11:45:12 +0200 Subject: [PATCH 3/3] squash: remove obsolete else if's --- lib/internal/crypto/diffiehellman.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/internal/crypto/diffiehellman.js b/lib/internal/crypto/diffiehellman.js index 37858bfb2c3bcd..dad7a903b26a5e 100644 --- a/lib/internal/crypto/diffiehellman.js +++ b/lib/internal/crypto/diffiehellman.js @@ -222,9 +222,9 @@ function getFormat(format) { if (format) { if (format === 'compressed') return POINT_CONVERSION_COMPRESSED; - else if (format === 'hybrid') + if (format === 'hybrid') return POINT_CONVERSION_HYBRID; - else if (format !== 'uncompressed') + if (format !== 'uncompressed') throw new ERR_CRYPTO_ECDH_INVALID_FORMAT(format); } return POINT_CONVERSION_UNCOMPRESSED;