crypto: simplify diffiehellman getFormat function

This commit aims to simplify the getFormat function in
diffiehellman.js.

PR-URL: https://github.com/nodejs/node/pull/20246
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Daniel Bevenius 2018-04-24 08:45:35 +02:00
parent 2a30bfe295
commit 3b8ab2ac7f

View File

@ -219,21 +219,15 @@ function encode(buffer, encoding) {
} }
function getFormat(format) { function getFormat(format) {
let f;
if (format) { if (format) {
if (format === 'compressed') if (format === 'compressed')
f = POINT_CONVERSION_COMPRESSED; return POINT_CONVERSION_COMPRESSED;
else if (format === 'hybrid') if (format === 'hybrid')
f = POINT_CONVERSION_HYBRID; return POINT_CONVERSION_HYBRID;
// Default if (format !== 'uncompressed')
else if (format === 'uncompressed')
f = POINT_CONVERSION_UNCOMPRESSED;
else
throw new ERR_CRYPTO_ECDH_INVALID_FORMAT(format); throw new ERR_CRYPTO_ECDH_INVALID_FORMAT(format);
} else {
f = POINT_CONVERSION_UNCOMPRESSED;
} }
return f; return POINT_CONVERSION_UNCOMPRESSED;
} }
module.exports = { module.exports = {