0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-03-03 09:31:22 -05:00

fix(ext/crypto): key generation based on AES key length (#12146)

This commit is contained in:
Divy Srivastava 2021-10-06 14:54:41 +05:30 committed by GitHub
parent 3aa8591595
commit b033a7a6d4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -222,7 +222,8 @@ pub async fn op_crypto_generate_key(
| Algorithm::AesGcm
| Algorithm::AesKw => {
let length = args.length.ok_or_else(not_supported)?;
let mut key_data = vec![0u8; length];
// Caller must guarantee divisibility by 8
let mut key_data = vec![0u8; length / 8];
let rng = RingRand::SystemRandom::new();
rng.fill(&mut key_data).map_err(|_| {
custom_error("DOMExceptionOperationError", "Key generation failed")