diff --git a/lib/internal/crypto/hash.js b/lib/internal/crypto/hash.js index c8e9af003086c8..57fcb63518d52d 100644 --- a/lib/internal/crypto/hash.js +++ b/lib/internal/crypto/hash.js @@ -14,7 +14,6 @@ const { } = internalBinding('crypto'); const { - getDefaultEncoding, getStringOption, jobPromise, normalizeHashName, @@ -95,8 +94,6 @@ Hash.prototype._flush = function _flush(callback) { }; Hash.prototype.update = function update(data, encoding) { - encoding = encoding || getDefaultEncoding(); - const state = this[kState]; if (state[kFinalized]) throw new ERR_CRYPTO_HASH_FINALIZED(); @@ -118,10 +115,9 @@ Hash.prototype.digest = function digest(outputEncoding) { const state = this[kState]; if (state[kFinalized]) throw new ERR_CRYPTO_HASH_FINALIZED(); - outputEncoding = outputEncoding || getDefaultEncoding(); - // Explicit conversion for backward compatibility. - const ret = this[kHandle].digest(`${outputEncoding}`); + // Explicit conversion of truthy values for backward compatibility. + const ret = this[kHandle].digest(outputEncoding && `${outputEncoding}`); state[kFinalized] = true; return ret; }; @@ -147,15 +143,16 @@ Hmac.prototype.update = Hash.prototype.update; Hmac.prototype.digest = function digest(outputEncoding) { const state = this[kState]; - outputEncoding = outputEncoding || getDefaultEncoding(); if (state[kFinalized]) { const buf = Buffer.from(''); - return outputEncoding === 'buffer' ? buf : buf.toString(outputEncoding); + if (outputEncoding && outputEncoding !== 'buffer') + return buf.toString(outputEncoding); + return buf; } - // Explicit conversion for backward compatibility. - const ret = this[kHandle].digest(`${outputEncoding}`); + // Explicit conversion of truthy values for backward compatibility. + const ret = this[kHandle].digest(outputEncoding && `${outputEncoding}`); state[kFinalized] = true; return ret; };