33const {
44 ObjectSetPrototypeOf,
55 ReflectApply,
6+ StringPrototypeReplace,
67 StringPrototypeToLowerCase,
78 Symbol,
89} = primordials ;
@@ -33,6 +34,8 @@ const {
3334 lazyDOMException,
3435 normalizeEncoding,
3536 encodingsMap,
37+ isPendingDeprecation,
38+ getDeprecationWarningEmitter,
3639} = require ( 'internal/util' ) ;
3740
3841const {
@@ -63,6 +66,22 @@ const LazyTransform = require('internal/streams/lazy_transform');
6366const kState = Symbol ( 'kState' ) ;
6467const kFinalized = Symbol ( 'kFinalized' ) ;
6568
69+ /**
70+ * @param {string } name
71+ */
72+ function normalizeAlgorithm ( name ) {
73+ return StringPrototypeReplace ( StringPrototypeToLowerCase ( name ) , '-' , '' ) ;
74+ }
75+
76+ let warned = false ;
77+ const emitDeprecationWarning = getDeprecationWarningEmitter (
78+ 'DEP0198' ,
79+ 'Creating SHAKE128/256 digests without an explicit options.outputLength is deprecated.' ,
80+ undefined ,
81+ false ,
82+ isPendingDeprecation ,
83+ ) ;
84+
6685function Hash ( algorithm , options ) {
6786 if ( ! new . target )
6887 return new Hash ( algorithm , options ) ;
@@ -80,6 +99,13 @@ function Hash(algorithm, options) {
8099 this [ kState ] = {
81100 [ kFinalized ] : false ,
82101 } ;
102+ if ( ! warned && ! isCopy && xofLen === undefined ) {
103+ const normalized = normalizeAlgorithm ( algorithm ) ;
104+ if ( normalized === 'shake128' || normalized === 'shake256' ) {
105+ emitDeprecationWarning ( ) ;
106+ warned = true ;
107+ }
108+ }
83109 ReflectApply ( LazyTransform , this , [ options ] ) ;
84110}
85111
@@ -213,6 +239,12 @@ function hash(algorithm, input, outputEncoding = 'hex') {
213239 }
214240 }
215241 }
242+ // TODO: ideally we have to ship https://github.com/nodejs/node/pull/58121 so
243+ // that a proper DEP0198 deprecation can be done here as well.
244+ const normalizedAlgorithm = normalizeAlgorithm ( algorithm ) ;
245+ if ( normalizedAlgorithm === 'shake128' || normalizedAlgorithm === 'shake256' ) {
246+ return new Hash ( algorithm ) . update ( input ) . digest ( normalized ) ;
247+ }
216248 return oneShotDigest ( algorithm , getCachedHashId ( algorithm ) , getHashCache ( ) ,
217249 input , normalized , encodingsMap [ normalized ] ) ;
218250}
0 commit comments