From ccaba29b320656f6449ad9592e0ae6d8d02aa34f Mon Sep 17 00:00:00 2001 From: marco-ippolito Date: Mon, 26 Feb 2024 12:03:01 +0100 Subject: [PATCH] crypto: runtime deprecate Hash constructor --- 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 ef54e200f814ad..f4bd658a56ad3e 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 ab9b9d99e11b8b..55a461a638be64 100644 --- a/lib/crypto.js +++ b/lib/crypto.js @@ -229,7 +229,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 af2146982c7a3b..83218c105a4596 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'], + ] + }); +}