mirror of
https://github.com/nodejs/node.git
synced 2026-11-21 12:59:16 -05:00
Signed-off-by: Filip Skokan <panva.ip@gmail.com> PR-URL: https://github.com/nodejs/node/pull/63255 Refs: https://github.com/electron/electron/issues/36256 Refs: https://github.com/electron/electron/issues/41720 Refs: https://github.com/electron/electron/pull/51127 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
40 lines
895 B
JavaScript
40 lines
895 B
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
|
|
if (!common.hasCrypto)
|
|
common.skip('missing crypto');
|
|
|
|
const assert = require('assert');
|
|
const { hasOpenSSL } = require('../common/crypto');
|
|
const { subtle } = globalThis.crypto;
|
|
|
|
async function test(algorithmName, keyLength, ivLength, format = 'raw') {
|
|
const key = await subtle.importKey(
|
|
format,
|
|
new Uint8Array(keyLength),
|
|
{ name: algorithmName },
|
|
false,
|
|
['encrypt', 'decrypt'],
|
|
);
|
|
|
|
const data = new Uint8Array(32);
|
|
data.buffer.transfer();
|
|
|
|
await assert.rejects(
|
|
subtle.decrypt({ name: algorithmName, iv: new Uint8Array(ivLength) }, key, data),
|
|
{ name: 'OperationError' },
|
|
);
|
|
}
|
|
|
|
const tests = [
|
|
test('AES-GCM', 32, 12),
|
|
test('ChaCha20-Poly1305', 32, 12, 'raw-secret'),
|
|
];
|
|
|
|
if (hasOpenSSL(3)) {
|
|
tests.push(test('AES-OCB', 32, 12, 'raw-secret'));
|
|
}
|
|
|
|
Promise.all(tests).then(common.mustCall());
|