mirror of
https://github.com/nodejs/node.git
synced 2026-11-24 21:50:36 -05:00
crypto: read algorithm name property only once in normalizeAlgorithm
PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
1 parent
2b74812c3c
commit
e1ca754de0
2 files changed
+39
-4
No files matched your search
@@ -565,10 +565,13 @@ function normalizeAlgorithm(algorithm, op) {
|
||||
return { name: algName };
|
||||
|
||||
// 6.
|
||||
const normalizedAlgorithm = webidl.converters[desiredType](algorithm, {
|
||||
prefix: 'Failed to normalize algorithm',
|
||||
context: 'passed algorithm',
|
||||
});
|
||||
const normalizedAlgorithm = webidl.converters[desiredType](
|
||||
{ __proto__: algorithm, name: algName },
|
||||
{
|
||||
prefix: 'Failed to normalize algorithm',
|
||||
context: 'passed algorithm',
|
||||
},
|
||||
);
|
||||
// 7.
|
||||
normalizedAlgorithm.name = algName;
|
||||
|
||||
|
||||
@@ -17,3 +17,35 @@ const {
|
||||
assert.strictEqual(normalizeAlgorithm(algorithm, 'sign') !== algorithm, true);
|
||||
assert.deepStrictEqual(algorithm, { name: 'ECDSA', hash: 'SHA-256' });
|
||||
}
|
||||
|
||||
// The algorithm name getter should only be invoked once during
|
||||
// normalizeAlgorithm, including for algorithms with a non-null desiredType
|
||||
// where step 6 runs the specialized dictionary converter.
|
||||
// Refs: https://github.com/web-platform-tests/wpt/pull/57614#pullrequestreview-3808145365
|
||||
{
|
||||
let nameReadCount = 0;
|
||||
const algorithm = {
|
||||
get name() {
|
||||
nameReadCount++;
|
||||
return 'AES-GCM';
|
||||
},
|
||||
iv: new Uint8Array(12),
|
||||
};
|
||||
const normalized = normalizeAlgorithm(algorithm, 'encrypt');
|
||||
assert.strictEqual(normalized.name, 'AES-GCM');
|
||||
assert.strictEqual(nameReadCount, 1);
|
||||
}
|
||||
|
||||
{
|
||||
let nameReadCount = 0;
|
||||
const algorithm = {
|
||||
get name() {
|
||||
nameReadCount++;
|
||||
return 'ECDSA';
|
||||
},
|
||||
hash: 'SHA-256',
|
||||
};
|
||||
const normalized = normalizeAlgorithm(algorithm, 'sign');
|
||||
assert.strictEqual(normalized.name, 'ECDSA');
|
||||
assert.strictEqual(nameReadCount, 1);
|
||||
}
|
||||
Reference in new issue
Block a user