mirror of
https://github.com/oven-sh/bun
synced 2026-02-10 10:58:56 +00:00
Co-authored-by: Jarred-Sumner <709451+Jarred-Sumner@users.noreply.github.com> Co-authored-by: Dylan Conway <dylan.conway567@gmail.com>
32 lines
861 B
JavaScript
32 lines
861 B
JavaScript
const { AsyncLocalStorage } = require("async_hooks");
|
|
const crypto = require("crypto");
|
|
|
|
const asyncLocalStorage = new AsyncLocalStorage();
|
|
|
|
asyncLocalStorage.run({ test: "crypto.cipher" }, () => {
|
|
const algorithm = "aes-256-cbc";
|
|
const key = crypto.randomBytes(32);
|
|
const iv = crypto.randomBytes(16);
|
|
|
|
const cipher = crypto.createCipheriv(algorithm, key, iv);
|
|
|
|
cipher.on("readable", () => {
|
|
if (asyncLocalStorage.getStore()?.test !== "crypto.cipher") {
|
|
console.error("FAIL: crypto cipher readable event lost context");
|
|
process.exit(1);
|
|
}
|
|
cipher.read();
|
|
});
|
|
|
|
cipher.on("end", () => {
|
|
if (asyncLocalStorage.getStore()?.test !== "crypto.cipher") {
|
|
console.error("FAIL: crypto cipher end event lost context");
|
|
process.exit(1);
|
|
}
|
|
process.exit(0);
|
|
});
|
|
|
|
cipher.write("test data");
|
|
cipher.end();
|
|
});
|