Skip to content

Commit 391d2f8

Browse files
danbevMylesBorins
authored andcommitted
crypto: simplify diffiehellman getFormat function
This commit aims to simplify the getFormat function in diffiehellman.js. PR-URL: #20246 Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 7f6172b commit 391d2f8

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

lib/internal/crypto/diffiehellman.js

+5-11
Original file line numberDiff line numberDiff line change
@@ -219,21 +219,15 @@ function encode(buffer, encoding) {
219219
}
220220

221221
function getFormat(format) {
222-
let f;
223222
if (format) {
224223
if (format === 'compressed')
225-
f = POINT_CONVERSION_COMPRESSED;
226-
else if (format === 'hybrid')
227-
f = POINT_CONVERSION_HYBRID;
228-
// Default
229-
else if (format === 'uncompressed')
230-
f = POINT_CONVERSION_UNCOMPRESSED;
231-
else
224+
return POINT_CONVERSION_COMPRESSED;
225+
if (format === 'hybrid')
226+
return POINT_CONVERSION_HYBRID;
227+
if (format !== 'uncompressed')
232228
throw new ERR_CRYPTO_ECDH_INVALID_FORMAT(format);
233-
} else {
234-
f = POINT_CONVERSION_UNCOMPRESSED;
235229
}
236-
return f;
230+
return POINT_CONVERSION_UNCOMPRESSED;
237231
}
238232

239233
module.exports = {

0 commit comments

Comments
 (0)