From 2fa30b8aba9e1fa24782629e6f2c0e9121603c43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kat=20March=C3=A1n?= Date: Fri, 16 Feb 2018 14:35:52 -0800 Subject: [PATCH] fix(hashes): filter hash priority list by available hashes --- index.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 8527433..5418256 100644 --- a/index.js +++ b/index.js @@ -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', @@ -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