diff --git a/doc/api/deprecations.md b/doc/api/deprecations.md index a164ab7f35043a..58862c2711f77e 100644 --- a/doc/api/deprecations.md +++ b/doc/api/deprecations.md @@ -4562,12 +4562,15 @@ removed in a future version of Node.js. -Type: Documentation-only +Type: Runtime Calling `hmac.digest()` more than once returns an empty buffer instead of throwing an error. This behavior is inconsistent with `hash.digest()` and diff --git a/lib/internal/crypto/hash.js b/lib/internal/crypto/hash.js index d47f7518f06260..2331d0bc061218 100644 --- a/lib/internal/crypto/hash.js +++ b/lib/internal/crypto/hash.js @@ -87,6 +87,13 @@ const maybeEmitDeprecationWarning = getDeprecationWarningEmitter( }, ); +const emitHmacDigestDeprecation = getDeprecationWarningEmitter( + 'DEP0206', + 'Calling digest() on an already-finalized Hmac instance is deprecated.', + undefined, + false, +); + 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]) { + emitHmacDigestDeprecation(); const buf = Buffer.from(''); if (outputEncoding && outputEncoding !== 'buffer') return buf.toString(outputEncoding);