Skip to content

Commit

Permalink
crypto: simplify diffiehellman getFormat function
Browse files Browse the repository at this point in the history
This commit aims to simplify the getFormat function in
diffiehellman.js.

PR-URL: #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>
  • Loading branch information
danbev authored and MylesBorins committed May 4, 2018
1 parent 7f6172b commit 391d2f8
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions lib/internal/crypto/diffiehellman.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,21 +219,15 @@ function encode(buffer, encoding) {
}

function getFormat(format) {
let f;
if (format) {
if (format === 'compressed')
f = POINT_CONVERSION_COMPRESSED;
else if (format === 'hybrid')
f = POINT_CONVERSION_HYBRID;
// Default
else if (format === 'uncompressed')
f = POINT_CONVERSION_UNCOMPRESSED;
else
return POINT_CONVERSION_COMPRESSED;
if (format === 'hybrid')
return POINT_CONVERSION_HYBRID;
if (format !== 'uncompressed')
throw new ERR_CRYPTO_ECDH_INVALID_FORMAT(format);
} else {
f = POINT_CONVERSION_UNCOMPRESSED;
}
return f;
return POINT_CONVERSION_UNCOMPRESSED;
}

module.exports = {
Expand Down

0 comments on commit 391d2f8

Please sign in to comment.