From 0d8223aef6bc622dc4cdfee6f529bed0cae37c4c Mon Sep 17 00:00:00 2001 From: Ishan Date: Mon, 22 Jul 2024 12:15:19 +0530 Subject: [PATCH] Review comment update - refactor to avoid lookup every time and to ensure consistency in case cfg changes --- lib/client.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/client.js b/lib/client.js index e6f860ad..aa94ace0 100644 --- a/lib/client.js +++ b/lib/client.js @@ -273,12 +273,14 @@ class Client extends EventEmitter { let hostVerifier; if (typeof cfg.hostVerifier === 'function') { const hashCb = cfg.hostVerifier; - hostVerifier = (key, verify) => { + let hashAlgo; if (HASHES.indexOf(cfg.hostHash) !== -1) { - // Default to old behavior of hashing on user's behalf - const hasher = createHash(cfg.hostHash).update(key); - key = hasher.digest('hex'); - } + // Default to old behavior of hashing on user's behalf + hashAlgo = cfg.hostHash; + } + hostVerifier = (key, verify) => { + if (hashAlgo) + key = createHash(hashAlgo).update(key).digest('hex'); const ret = hashCb(key, verify); if (ret !== undefined) verify(ret);