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,25 @@ 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+ const  maybeEmitDeprecationWarning  =  getDeprecationWarningEmitter ( 
77+   'DEP0198' , 
78+   'Creating SHAKE128/256 digests without an explicit options.outputLength is deprecated.' , 
79+   undefined , 
80+   false , 
81+   ( algorithm )  =>  { 
82+     if  ( ! isPendingDeprecation ( ) )  return  false ; 
83+     const  normalized  =  normalizeAlgorithm ( algorithm ) ; 
84+     return  normalized  ===  'shake128'  ||  normalized  ===  'shake256' ; 
85+   } , 
86+ ) ; 
87+ 
6688function  Hash ( algorithm ,  options )  { 
6789  if  ( ! new . target ) 
6890    return  new  Hash ( algorithm ,  options ) ; 
@@ -80,6 +102,9 @@ function Hash(algorithm, options) {
80102  this [ kState ]  =  { 
81103    [ kFinalized ] : false , 
82104  } ; 
105+   if  ( ! isCopy  &&  xofLen  ===  undefined )  { 
106+     maybeEmitDeprecationWarning ( algorithm ) ; 
107+   } 
83108  ReflectApply ( LazyTransform ,  this ,  [ options ] ) ; 
84109} 
85110
@@ -213,6 +238,12 @@ function hash(algorithm, input, outputEncoding = 'hex') {
213238      } 
214239    } 
215240  } 
241+   // TODO: ideally we have to ship https://github.com/nodejs/node/pull/58121 so 
242+   // that a proper DEP0198 deprecation can be done here as well. 
243+   const  normalizedAlgorithm  =  normalizeAlgorithm ( algorithm ) ; 
244+   if  ( normalizedAlgorithm  ===  'shake128'  ||  normalizedAlgorithm  ===  'shake256' )  { 
245+     return  new  Hash ( algorithm ) . update ( input ) . digest ( normalized ) ; 
246+   } 
216247  return  oneShotDigest ( algorithm ,  getCachedHashId ( algorithm ) ,  getHashCache ( ) , 
217248                       input ,  normalized ,  encodingsMap [ normalized ] ) ; 
218249} 
0 commit comments