mirror of
https://github.com/nodejs/node.git
synced 2026-10-28 18:25:13 +08:00
Reject non-ASCII equivalents of registered Web Crypto algorithm names. Skip the character scan when the input already uses the canonical name. Signed-off-by: Filip Skokan <panva.ip@gmail.com> Assisted-by: Codex PR-URL: https://github.com/nodejs/node/pull/66237 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Aviv Keller <me@aviv.sh>
25 lines
999 B
JavaScript
25 lines
999 B
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
if (!common.hasCrypto)
|
|
common.skip('missing crypto');
|
|
|
|
const assert = require('assert');
|
|
const { subtle } = globalThis.crypto;
|
|
|
|
(async () => {
|
|
const data = new Uint8Array(0);
|
|
assert.deepStrictEqual(await subtle.digest('sha-256', data),
|
|
await subtle.digest('SHA-256', data));
|
|
for (const name of ['\u017fha-256', 'SHA-256\u0131']) {
|
|
await assert.rejects(subtle.digest(name, data), { name: 'NotSupportedError' });
|
|
assert.strictEqual(SubtleCrypto.supports('digest', name), false);
|
|
}
|
|
await assert.rejects(subtle.generateKey({ name: 'AE\u017f-GCM', length: 128 },
|
|
false, ['encrypt']),
|
|
{ name: 'NotSupportedError' });
|
|
await assert.rejects(subtle.importKey('raw-secret', data, 'Argon2\u0131d',
|
|
false, ['deriveBits']),
|
|
{ name: 'NotSupportedError' });
|
|
})().then(common.mustCall());
|