diff --git a/lib/internal/crypto/hash.js b/lib/internal/crypto/hash.js index d47f7518f06260..487bb7e669ca36 100644 --- a/lib/internal/crypto/hash.js +++ b/lib/internal/crypto/hash.js @@ -87,6 +87,13 @@ const maybeEmitDeprecationWarning = getDeprecationWarningEmitter( }, ); +const maybeEmitHMACMultipleDigestDeprecationWarning = + getDeprecationWarningEmitter( + 'DEP0208', + 'Calling hmac.digest() multiple times without re-initialization is ' + + 'deprecated and will throw an error in a future version.', + ); + function Hash(algorithm, options) { if (!new.target) return new Hash(algorithm, options); @@ -186,6 +193,7 @@ Hmac.prototype.digest = function digest(outputEncoding) { const state = this[kState]; if (state[kFinalized]) { + maybeEmitHMACMultipleDigestDeprecationWarning(); const buf = Buffer.from(''); if (outputEncoding && outputEncoding !== 'buffer') return buf.toString(outputEncoding);