Skip to content

Commit 2fa30b8

Browse files
committed
fix(hashes): filter hash priority list by available hashes
1 parent d56c654 commit 2fa30b8

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

index.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,8 @@ function createIntegrity (opts) {
331331
}
332332
}
333333

334+
const NODE_HASHES = new Set(crypto.getHashes())
335+
334336
// This is a Best Effort™ at a reasonable priority for hash algos
335337
const DEFAULT_PRIORITY = [
336338
'md5', 'whirlpool', 'sha1', 'sha224', 'sha256', 'sha384', 'sha512',
@@ -339,7 +341,8 @@ const DEFAULT_PRIORITY = [
339341
'sha3',
340342
'sha3-256', 'sha3-384', 'sha3-512',
341343
'sha3_256', 'sha3_384', 'sha3_512'
342-
]
344+
].filter(algo => NODE_HASHES.has(algo))
345+
343346
function getPrioritizedHash (algo1, algo2) {
344347
return DEFAULT_PRIORITY.indexOf(algo1.toLowerCase()) >= DEFAULT_PRIORITY.indexOf(algo2.toLowerCase())
345348
? algo1

0 commit comments

Comments
 (0)