summaryrefslogtreecommitdiff
path: root/ext/crypto/lib.rs
diff options
context:
space:
mode:
authorLuca Casonato <hello@lcas.dev>2021-11-22 23:58:21 +0100
committerGitHub <noreply@github.com>2021-11-22 23:58:21 +0100
commit71ceca0ffc4239b62431550b4d9952d909d342ec (patch)
tree6db6a18e1d88adbaabfa37f69cd4de8a8d277943 /ext/crypto/lib.rs
parent3cc724c9bae94c2f79dd4a902782a66f688a1e61 (diff)
fix(ext/crypto): don't panic on decryption failure (#12840)
Diffstat (limited to 'ext/crypto/lib.rs')
-rw-r--r--ext/crypto/lib.rs21
1 files changed, 18 insertions, 3 deletions
diff --git a/ext/crypto/lib.rs b/ext/crypto/lib.rs
index b0cd7ef06..dcf03d64c 100644
--- a/ext/crypto/lib.rs
+++ b/ext/crypto/lib.rs
@@ -1603,7 +1603,12 @@ pub async fn op_crypto_decrypt_key(
block_modes::Cbc<aes::Aes128, block_modes::block_padding::Pkcs7>;
let cipher = Aes128Cbc::new_from_slices(key, &iv)?;
- cipher.decrypt_vec(data)?
+ cipher.decrypt_vec(data).map_err(|_| {
+ custom_error(
+ "DOMExceptionOperationError",
+ "Decryption failed".to_string(),
+ )
+ })?
}
192 => {
// Section 10.3 Step 2 of RFC 2315 https://www.rfc-editor.org/rfc/rfc2315
@@ -1611,7 +1616,12 @@ pub async fn op_crypto_decrypt_key(
block_modes::Cbc<aes::Aes192, block_modes::block_padding::Pkcs7>;
let cipher = Aes192Cbc::new_from_slices(key, &iv)?;
- cipher.decrypt_vec(data)?
+ cipher.decrypt_vec(data).map_err(|_| {
+ custom_error(
+ "DOMExceptionOperationError",
+ "Decryption failed".to_string(),
+ )
+ })?
}
256 => {
// Section 10.3 Step 2 of RFC 2315 https://www.rfc-editor.org/rfc/rfc2315
@@ -1619,7 +1629,12 @@ pub async fn op_crypto_decrypt_key(
block_modes::Cbc<aes::Aes256, block_modes::block_padding::Pkcs7>;
let cipher = Aes256Cbc::new_from_slices(key, &iv)?;
- cipher.decrypt_vec(data)?
+ cipher.decrypt_vec(data).map_err(|_| {
+ custom_error(
+ "DOMExceptionOperationError",
+ "Decryption failed".to_string(),
+ )
+ })?
}
_ => unreachable!(),
};