Skip to content

Commit

Permalink
Review comment update
Browse files Browse the repository at this point in the history
 - refactor to avoid lookup every time and to ensure consistency in case cfg changes
  • Loading branch information
Ishan committed Jul 22, 2024
1 parent 1bd608d commit 0d8223a
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 0d8223a

Please sign in to comment.