3
3
const {
4
4
ObjectSetPrototypeOf,
5
5
ReflectApply,
6
+ StringPrototypeReplace,
6
7
StringPrototypeToLowerCase,
7
8
Symbol,
8
9
} = primordials ;
@@ -33,6 +34,8 @@ const {
33
34
lazyDOMException,
34
35
normalizeEncoding,
35
36
encodingsMap,
37
+ isPendingDeprecation,
38
+ getDeprecationWarningEmitter,
36
39
} = require ( 'internal/util' ) ;
37
40
38
41
const {
@@ -63,6 +66,25 @@ const LazyTransform = require('internal/streams/lazy_transform');
63
66
const kState = Symbol ( 'kState' ) ;
64
67
const kFinalized = Symbol ( 'kFinalized' ) ;
65
68
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
+
66
88
function Hash ( algorithm , options ) {
67
89
if ( ! new . target )
68
90
return new Hash ( algorithm , options ) ;
@@ -80,6 +102,9 @@ function Hash(algorithm, options) {
80
102
this [ kState ] = {
81
103
[ kFinalized ] : false ,
82
104
} ;
105
+ if ( ! isCopy && xofLen === undefined ) {
106
+ maybeEmitDeprecationWarning ( algorithm ) ;
107
+ }
83
108
ReflectApply ( LazyTransform , this , [ options ] ) ;
84
109
}
85
110
@@ -213,6 +238,12 @@ function hash(algorithm, input, outputEncoding = 'hex') {
213
238
}
214
239
}
215
240
}
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
+ }
216
247
return oneShotDigest ( algorithm , getCachedHashId ( algorithm ) , getHashCache ( ) ,
217
248
input , normalized , encodingsMap [ normalized ] ) ;
218
249
}
0 commit comments