Skip to content

Commit 0c9bcf8

Browse files
committed
throw for bad output length
1 parent 6e18d3d commit 0c9bcf8

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

ext/node/ops/crypto/digest.rs

+14-2
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,22 @@ impl Hash {
203203
"shake128" => return Ok(Shake128(Default::default(), output_length)),
204204
"shake256" => return Ok(Shake256(Default::default(), output_length)),
205205
"sha256" => {
206-
return Ok(Hash::FixedSize(Box::new(ring_sha2::RingSha256::new())))
206+
let digest = ring_sha2::RingSha256::new();
207+
if let Some(length) = output_length {
208+
if length != digest.output_size() {
209+
return Err(HashError::OutputLengthMismatch);
210+
}
211+
}
212+
return Ok(Hash::FixedSize(Box::new(digest)));
207213
}
208214
"sha512" => {
209-
return Ok(Hash::FixedSize(Box::new(ring_sha2::RingSha512::new())))
215+
let digest = ring_sha2::RingSha512::new();
216+
if let Some(length) = output_length {
217+
if length != digest.output_size() {
218+
return Err(HashError::OutputLengthMismatch);
219+
}
220+
}
221+
return Ok(Hash::FixedSize(Box::new(digest)));
210222
}
211223
_ => {}
212224
}

0 commit comments

Comments
 (0)