diff options
Diffstat (limited to 'ext/node')
-rw-r--r-- | ext/node/Cargo.toml | 2 | ||||
-rw-r--r-- | ext/node/ops/crypto/cipher.rs | 36 |
2 files changed, 25 insertions, 13 deletions
diff --git a/ext/node/Cargo.toml b/ext/node/Cargo.toml index 800b8f591..ce9714954 100644 --- a/ext/node/Cargo.toml +++ b/ext/node/Cargo.toml @@ -17,7 +17,7 @@ path = "lib.rs" sync_fs = ["deno_package_json/sync", "node_resolver/sync"] [dependencies] -aead-gcm-stream = "0.1" +aead-gcm-stream = "0.3" aes.workspace = true async-trait.workspace = true base64.workspace = true diff --git a/ext/node/ops/crypto/cipher.rs b/ext/node/ops/crypto/cipher.rs index ca13fdcd8..94bd5780e 100644 --- a/ext/node/ops/crypto/cipher.rs +++ b/ext/node/ops/crypto/cipher.rs @@ -137,16 +137,22 @@ impl Cipher { "aes-192-ecb" => Aes192Ecb(Box::new(ecb::Encryptor::new(key.into()))), "aes-256-ecb" => Aes256Ecb(Box::new(ecb::Encryptor::new(key.into()))), "aes-128-gcm" => { - let mut cipher = - aead_gcm_stream::AesGcm::<aes::Aes128>::new(key.into()); - cipher.init(iv.try_into()?); + if iv.len() != 12 { + return Err(type_error("IV length must be 12 bytes")); + } + + let cipher = + aead_gcm_stream::AesGcm::<aes::Aes128>::new(key.into(), iv); Aes128Gcm(Box::new(cipher)) } "aes-256-gcm" => { - let mut cipher = - aead_gcm_stream::AesGcm::<aes::Aes256>::new(key.into()); - cipher.init(iv.try_into()?); + if iv.len() != 12 { + return Err(type_error("IV length must be 12 bytes")); + } + + let cipher = + aead_gcm_stream::AesGcm::<aes::Aes256>::new(key.into(), iv); Aes256Gcm(Box::new(cipher)) } @@ -320,16 +326,22 @@ impl Decipher { "aes-192-ecb" => Aes192Ecb(Box::new(ecb::Decryptor::new(key.into()))), "aes-256-ecb" => Aes256Ecb(Box::new(ecb::Decryptor::new(key.into()))), "aes-128-gcm" => { - let mut decipher = - aead_gcm_stream::AesGcm::<aes::Aes128>::new(key.into()); - decipher.init(iv.try_into()?); + if iv.len() != 12 { + return Err(type_error("IV length must be 12 bytes")); + } + + let decipher = + aead_gcm_stream::AesGcm::<aes::Aes128>::new(key.into(), iv); Aes128Gcm(Box::new(decipher)) } "aes-256-gcm" => { - let mut decipher = - aead_gcm_stream::AesGcm::<aes::Aes256>::new(key.into()); - decipher.init(iv.try_into()?); + if iv.len() != 12 { + return Err(type_error("IV length must be 12 bytes")); + } + + let decipher = + aead_gcm_stream::AesGcm::<aes::Aes256>::new(key.into(), iv); Aes256Gcm(Box::new(decipher)) } |