Skip to content

Commit

Permalink
fix(hashes): filter hash priority list by available hashes
Browse files Browse the repository at this point in the history
  • Loading branch information
zkat committed Feb 16, 2018
1 parent d56c654 commit 2fa30b8
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,8 @@ function createIntegrity (opts) {
}
}

const NODE_HASHES = new Set(crypto.getHashes())

// This is a Best Effort™ at a reasonable priority for hash algos
const DEFAULT_PRIORITY = [
'md5', 'whirlpool', 'sha1', 'sha224', 'sha256', 'sha384', 'sha512',
Expand All @@ -339,7 +341,8 @@ const DEFAULT_PRIORITY = [
'sha3',
'sha3-256', 'sha3-384', 'sha3-512',
'sha3_256', 'sha3_384', 'sha3_512'
]
].filter(algo => NODE_HASHES.has(algo))

function getPrioritizedHash (algo1, algo2) {
return DEFAULT_PRIORITY.indexOf(algo1.toLowerCase()) >= DEFAULT_PRIORITY.indexOf(algo2.toLowerCase())
? algo1
Expand Down

0 comments on commit 2fa30b8

Please sign in to comment.