mirror of
https://github.com/nodejs/node.git
synced 2026-11-24 21:50:36 -05:00
PR-URL: https://github.com/nodejs/node/pull/62169 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
43 lines
956 B
JavaScript
43 lines
956 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),
|
|
];
|
|
|
|
if (hasOpenSSL(3)) {
|
|
tests.push(test('AES-OCB', 32, 12, 'raw-secret'));
|
|
}
|
|
|
|
if (!process.features.openssl_is_boringssl) {
|
|
tests.push(test('ChaCha20-Poly1305', 32, 12, 'raw-secret'));
|
|
}
|
|
|
|
Promise.all(tests).then(common.mustCall());
|