Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 93d7771

Browse filesBrowse files
panvaaduh95
authored andcommitted
crypto: read algorithm name property only once in normalizeAlgorithm
PR-URL: #62170 Refs: https://redirect.github.com/web-platform-tests/wpt/pull/57614#pullrequestreview-3808145365 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent 7d9db8c commit 93d7771
Copy full SHA for 93d7771

2 files changed

+39-4Lines changed: 39 additions & 4 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/internal/crypto/util.js‎

Copy file name to clipboardExpand all lines: lib/internal/crypto/util.js
+7-4Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -565,10 +565,13 @@ function normalizeAlgorithm(algorithm, op) {
565565
return { name: algName };
566566

567567
// 6.
568-
const normalizedAlgorithm = webidl.converters[desiredType](algorithm, {
569-
prefix: 'Failed to normalize algorithm',
570-
context: 'passed algorithm',
571-
});
568+
const normalizedAlgorithm = webidl.converters[desiredType](
569+
{ __proto__: algorithm, name: algName },
570+
{
571+
prefix: 'Failed to normalize algorithm',
572+
context: 'passed algorithm',
573+
},
574+
);
572575
// 7.
573576
normalizedAlgorithm.name = algName;
574577

Collapse file

‎test/parallel/test-webcrypto-util.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-webcrypto-util.js
+32Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,35 @@ const {
1717
assert.strictEqual(normalizeAlgorithm(algorithm, 'sign') !== algorithm, true);
1818
assert.deepStrictEqual(algorithm, { name: 'ECDSA', hash: 'SHA-256' });
1919
}
20+
21+
// The algorithm name getter should only be invoked once during
22+
// normalizeAlgorithm, including for algorithms with a non-null desiredType
23+
// where step 6 runs the specialized dictionary converter.
24+
// Refs: https://github.com/web-platform-tests/wpt/pull/57614#pullrequestreview-3808145365
25+
{
26+
let nameReadCount = 0;
27+
const algorithm = {
28+
get name() {
29+
nameReadCount++;
30+
return 'AES-GCM';
31+
},
32+
iv: new Uint8Array(12),
33+
};
34+
const normalized = normalizeAlgorithm(algorithm, 'encrypt');
35+
assert.strictEqual(normalized.name, 'AES-GCM');
36+
assert.strictEqual(nameReadCount, 1);
37+
}
38+
39+
{
40+
let nameReadCount = 0;
41+
const algorithm = {
42+
get name() {
43+
nameReadCount++;
44+
return 'ECDSA';
45+
},
46+
hash: 'SHA-256',
47+
};
48+
const normalized = normalizeAlgorithm(algorithm, 'sign');
49+
assert.strictEqual(normalized.name, 'ECDSA');
50+
assert.strictEqual(nameReadCount, 1);
51+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.