Skip to content

Commit 98ca450

Browse files
bartlomiejuclaude
andauthored
fix(ext/node): emit DEP0198 warning for SHAKE digests without outputLength (#32521)
## Summary - Emit `DeprecationWarning` (DEP0198) when creating SHAKE128/256 digests without an explicit `options.outputLength`, matching Node.js behavior with `--pending-deprecation` - Enables `test-crypto-default-shake-lengths.js` and `test-crypto-default-shake-lengths-oneshot.js` in node_compat --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent e0b1933 commit 98ca450

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

ext/node/polyfills/internal/crypto/hash.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import {
4343
NodeError,
4444
} from "ext:deno_node/internal/errors.ts";
4545
import LazyTransform from "ext:deno_node/internal/streams/lazy_transform.js";
46+
import process from "node:process";
4647
import {
4748
getDefaultEncoding,
4849
getHashBlockSize,
@@ -80,10 +81,24 @@ export function Hash(
8081
validateUint32(xofLen, "options.outputLength");
8182
}
8283

84+
const algoLower = isCopy ? undefined : algorithm.toLowerCase();
85+
86+
if (
87+
!isCopy && xofLen === undefined &&
88+
(algoLower === "shake128" ||
89+
algoLower === "shake256")
90+
) {
91+
process.emitWarning(
92+
"Creating SHAKE128/256 digests without an explicit options.outputLength is deprecated.",
93+
"DeprecationWarning",
94+
"DEP0198",
95+
);
96+
}
97+
8398
try {
8499
this[kHandle] = isCopy
85100
? op_node_hash_clone(algorithm, xofLen)
86-
: op_node_create_hash(algorithm.toLowerCase(), xofLen);
101+
: op_node_create_hash(algoLower, xofLen);
87102
} catch (err) {
88103
// TODO(lucacasonato): don't do this
89104
if (err.message === "Output length mismatch for non-extendable algorithm") {

tests/node_compat/config.jsonc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,8 @@
256256
"exitCode": 1,
257257
"output": "[WILDCARD]Unknown cipher id-aes128-wrap[WILDCARD]"
258258
},
259+
"parallel/test-crypto-default-shake-lengths.js": {},
260+
"parallel/test-crypto-default-shake-lengths-oneshot.js": {},
259261
"parallel/test-crypto-dh-constructor.js": {},
260262
"parallel/test-crypto-dh-leak.js": {},
261263
"parallel/test-crypto-dh-odd-key.js": {},

0 commit comments

Comments
 (0)