diff options
Diffstat (limited to 'lib/internal/crypto/hash.js')
-rw-r--r-- | lib/internal/crypto/hash.js | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/lib/internal/crypto/hash.js b/lib/internal/crypto/hash.js index 38b125e5f2..7e4a83ca93 100644 --- a/lib/internal/crypto/hash.js +++ b/lib/internal/crypto/hash.js @@ -25,7 +25,8 @@ const { ERR_CRYPTO_HASH_UPDATE_FAILED, ERR_INVALID_ARG_TYPE } = require('internal/errors').codes; -const { validateString, validateUint32 } = require('internal/validators'); +const { validateEncoding, validateString, validateUint32 } = + require('internal/validators'); const { normalizeEncoding } = require('internal/util'); const { isArrayBufferView } = require('internal/util/types'); const LazyTransform = require('internal/streams/lazy_transform'); @@ -61,6 +62,8 @@ 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(); @@ -74,7 +77,9 @@ Hash.prototype.update = function update(data, encoding) { data); } - if (!this[kHandle].update(data, encoding || getDefaultEncoding())) + validateEncoding(data, encoding); + + if (!this[kHandle].update(data, encoding)) throw new ERR_CRYPTO_HASH_UPDATE_FAILED(); return this; }; |