Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion doc/api/deprecations.md
Original file line number Diff line number Diff line change
Expand Up @@ -4565,9 +4565,12 @@ changes:
- version: v26.2.0
pr-url: https://github.com/nodejs/node/pull/63121
description: Documentation-only deprecation.
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/REPLACEME
description: Runtime deprecation.
-->

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
Expand Down
6 changes: 6 additions & 0 deletions lib/internal/crypto/hash.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ const maybeEmitDeprecationWarning = getDeprecationWarningEmitter(
},
);

const emitHmacDigestDeprecation = getDeprecationWarningEmitter(
'DEP0206',
'Calling Hmac.digest() more than once is deprecated.',
);

function Hash(algorithm, options) {
if (!new.target)
return new Hash(algorithm, options);
Expand Down Expand Up @@ -183,6 +188,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);
Expand Down
11 changes: 11 additions & 0 deletions test/parallel/test-crypto-hmac.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ assert.throws(
name: 'TypeError',
});

// Verify runtime deprecation warning for calling digest() more than once.
{
common.expectWarning(
'DeprecationWarning',
'Calling Hmac.digest() more than once is deprecated.',
'DEP0206');
const h = crypto.createHmac('sha1', 'key').update('data');
h.digest('hex');
h.digest('hex');
}

function testHmac(algo, key, data, expected) {
// FIPS does not support MD5.
if (crypto.getFips() && algo === 'md5')
Expand Down
Loading