From de0602d190cb24dab7e999841a39034a3b7ce941 Mon Sep 17 00:00:00 2001 From: Marco Ippolito Date: Tue, 12 Mar 2024 08:58:03 +0100 Subject: [PATCH] crypto: runtime deprecate Hash constructor PR-URL: https://github.com/nodejs/node/pull/51880 Reviewed-By: Yagiz Nizipli Reviewed-By: Filip Skokan Reviewed-By: Paolo Insogna Reviewed-By: Rafael Gonzaga --- doc/api/deprecations.md | 5 ++++- lib/crypto.js | 2 +- test/parallel/test-crypto-hash.js | 10 ++++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/doc/api/deprecations.md b/doc/api/deprecations.md index 0102c37e2d9..2f3f420d0d3 100644 --- a/doc/api/deprecations.md +++ b/doc/api/deprecations.md @@ -3563,12 +3563,15 @@ release lines. Please use [`dirent.parentPath`][] instead. -Type: Documentation-only +Type: Runtime Calling `Hash` class directly with `Hash()` or `new Hash()` is deprecated due to being internals, not intended for public use. diff --git a/lib/crypto.js b/lib/crypto.js index 8d49274b33f..c7cfdc841be 100644 --- a/lib/crypto.js +++ b/lib/crypto.js @@ -231,7 +231,7 @@ module.exports = { DiffieHellman, DiffieHellmanGroup, ECDH, - Hash, + Hash: deprecate(Hash, 'crypto.Hash constructor is deprecated.', 'DEP0179'), Hmac, KeyObject, Sign, diff --git a/test/parallel/test-crypto-hash.js b/test/parallel/test-crypto-hash.js index af2146982c7..83218c105a4 100644 --- a/test/parallel/test-crypto-hash.js +++ b/test/parallel/test-crypto-hash.js @@ -276,3 +276,13 @@ assert.throws( assert.strictEqual(a.digest('hex'), b.digest('hex')); assert.strictEqual(c.digest('hex'), d.digest('hex')); } + +{ + crypto.Hash('sha256'); + common.expectWarning({ + DeprecationWarning: [ + ['crypto.Hash constructor is deprecated.', + 'DEP0179'], + ] + }); +}