Files
node/test/parallel/test-webcrypto-algorithm-name-ascii.js
Filip Skokan f0811cade8 crypto: match algorithm names as ASCII
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>
2026-09-25 13:23:04 +00:00

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());