summaryrefslogtreecommitdiff
path: root/ext/crypto/lib.rs
diff options
context:
space:
mode:
authorupendra1997 <Upendra.upadhyay.97@gmail.com>2021-11-11 14:34:17 +0530
committerGitHub <noreply@github.com>2021-11-11 10:04:17 +0100
commite00bfecf960a7d1c60542e04d17c4e558083f8e9 (patch)
tree9e93293b92c71158915c36651ee421f328cf8c28 /ext/crypto/lib.rs
parenta2c8f554c415385f18d62867eb207ae2561802a7 (diff)
fix(crypto): handling large key length in HKDF (#12692)
Diffstat (limited to 'ext/crypto/lib.rs')
-rw-r--r--ext/crypto/lib.rs8
1 files changed, 6 insertions, 2 deletions
diff --git a/ext/crypto/lib.rs b/ext/crypto/lib.rs
index 2170e3c72..b0cd7ef06 100644
--- a/ext/crypto/lib.rs
+++ b/ext/crypto/lib.rs
@@ -876,10 +876,14 @@ pub async fn op_crypto_derive_bits(
let salt = hkdf::Salt::new(algorithm, salt);
let prk = salt.extract(&secret);
let info = &[&*info];
- let okm = prk.expand(info, HkdfOutput(length))?;
+ let okm = prk.expand(info, HkdfOutput(length)).map_err(|_e| {
+ custom_error(
+ "DOMExceptionOperationError",
+ "The length provided for HKDF is too large",
+ )
+ })?;
let mut r = vec![0u8; length];
okm.fill(&mut r)?;
-
Ok(r.into())
}
_ => Err(type_error("Unsupported algorithm".to_string())),