1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-26 16:09:27 -05:00

fix(node): propagate create cipher errors (#20280)

Fixes https://github.com/denoland/deno/issues/19002
This commit is contained in:
Divy Srivastava 2023-08-26 10:45:37 +05:30 committed by Bartek Iwańczuk
parent 4dcb410b9d
commit 999bc870f6
No known key found for this signature in database
GPG key ID: 0C6BCDDC3B3AD750
2 changed files with 30 additions and 0 deletions

View file

@ -199,3 +199,27 @@ Deno.test({
assertEquals(await text(stream), "foo".repeat(15)); assertEquals(await text(stream), "foo".repeat(15));
}, },
}); });
Deno.test({
name: "createCipheriv - invalid algorithm",
fn() {
assertThrows(
() =>
crypto.createCipheriv("foo", new Uint8Array(16), new Uint8Array(16)),
TypeError,
"Unknown cipher",
);
},
});
Deno.test({
name: "createDecipheriv - invalid algorithm",
fn() {
assertThrows(
() =>
crypto.createDecipheriv("foo", new Uint8Array(16), new Uint8Array(16)),
TypeError,
"Unknown cipher",
);
},
});

View file

@ -162,6 +162,9 @@ export class Cipheriv extends Transform implements Cipher {
}); });
this.#cache = new BlockModeCache(false); this.#cache = new BlockModeCache(false);
this.#context = ops.op_node_create_cipheriv(cipher, toU8(key), toU8(iv)); this.#context = ops.op_node_create_cipheriv(cipher, toU8(key), toU8(iv));
if (this.#context == 0) {
throw new TypeError("Unknown cipher");
}
} }
final(encoding: string = getDefaultEncoding()): Buffer | string { final(encoding: string = getDefaultEncoding()): Buffer | string {
@ -278,6 +281,9 @@ export class Decipheriv extends Transform implements Cipher {
}); });
this.#cache = new BlockModeCache(true); this.#cache = new BlockModeCache(true);
this.#context = ops.op_node_create_decipheriv(cipher, toU8(key), toU8(iv)); this.#context = ops.op_node_create_decipheriv(cipher, toU8(key), toU8(iv));
if (this.#context == 0) {
throw new TypeError("Unknown cipher");
}
} }
final(encoding: string = getDefaultEncoding()): Buffer | string { final(encoding: string = getDefaultEncoding()): Buffer | string {