diff options
Diffstat (limited to 'lib/internal/crypto/hash.js')
-rw-r--r-- | lib/internal/crypto/hash.js | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/lib/internal/crypto/hash.js b/lib/internal/crypto/hash.js index eccfb44569..b28f9fca13 100644 --- a/lib/internal/crypto/hash.js +++ b/lib/internal/crypto/hash.js @@ -34,7 +34,8 @@ const kFinalized = Symbol('kFinalized'); function Hash(algorithm, options) { if (!(this instanceof Hash)) return new Hash(algorithm, options); - validateString(algorithm, 'algorithm'); + if (!(algorithm instanceof _Hash)) + validateString(algorithm, 'algorithm'); const xofLen = typeof options === 'object' && options !== null ? options.outputLength : undefined; if (xofLen !== undefined) @@ -49,6 +50,14 @@ function Hash(algorithm, options) { Object.setPrototypeOf(Hash.prototype, LazyTransform.prototype); Object.setPrototypeOf(Hash, LazyTransform); +Hash.prototype.copy = function copy(options) { + const state = this[kState]; + if (state[kFinalized]) + throw new ERR_CRYPTO_HASH_FINALIZED(); + + return new Hash(this[kHandle], options); +}; + Hash.prototype._transform = function _transform(chunk, encoding, callback) { this[kHandle].update(chunk, encoding); callback(); |