mirror of
https://github.com/oven-sh/bun
synced 2026-02-11 03:18:53 +00:00
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com> Co-authored-by: Dave Caruso <me@paperdave.net>
40 lines
1.2 KiB
JavaScript
40 lines
1.2 KiB
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
if (!common.hasCrypto)
|
|
common.skip('missing crypto');
|
|
|
|
// Issue https://github.com/nodejs/node/issues/35263
|
|
// Description: Test that passing keyobject to worker thread does not crash.
|
|
const {
|
|
generateKeySync,
|
|
generateKeyPairSync,
|
|
} = require('crypto');
|
|
const { subtle } = globalThis.crypto;
|
|
|
|
const assert = require('assert');
|
|
|
|
const { Worker, isMainThread, workerData } = require('worker_threads');
|
|
|
|
if (isMainThread) {
|
|
(async () => {
|
|
const secretKey = generateKeySync('aes', { length: 128 });
|
|
const { publicKey, privateKey } = generateKeyPairSync('rsa', {
|
|
modulusLength: 1024
|
|
});
|
|
const cryptoKey = await subtle.generateKey(
|
|
{ name: 'AES-CBC', length: 128 }, false, ['encrypt']);
|
|
|
|
for (const key of [secretKey, publicKey, privateKey, cryptoKey]) {
|
|
new Worker(__filename, { workerData: key });
|
|
}
|
|
})().then(common.mustCall());
|
|
} else {
|
|
console.log(workerData);
|
|
assert.notDeepStrictEqual(workerData, {});
|
|
if (workerData instanceof CryptoKey) {
|
|
assert.deepStrictEqual(structuredClone(workerData), workerData);
|
|
} else {
|
|
assert(workerData.equals(structuredClone(workerData)));
|
|
}
|
|
}
|