mirror of
https://github.com/BLAKE3-team/BLAKE3
synced 2024-05-19 00:46:06 +02:00
test `b3sum --keyed` with bad key lengths
This commit is contained in:
parent
2465e0a935
commit
e366618d22
|
@ -304,13 +304,13 @@ fn read_key_from_stdin() -> Result<[u8; blake3::KEY_LEN]> {
|
||||||
.lock()
|
.lock()
|
||||||
.take(blake3::KEY_LEN as u64 + 1)
|
.take(blake3::KEY_LEN as u64 + 1)
|
||||||
.read_to_end(&mut bytes)?;
|
.read_to_end(&mut bytes)?;
|
||||||
if n < 32 {
|
if n < blake3::KEY_LEN {
|
||||||
bail!(
|
bail!(
|
||||||
"expected {} key bytes from stdin, found {}",
|
"expected {} key bytes from stdin, found {}",
|
||||||
blake3::KEY_LEN,
|
blake3::KEY_LEN,
|
||||||
n,
|
n,
|
||||||
)
|
)
|
||||||
} else if n > 32 {
|
} else if n > blake3::KEY_LEN {
|
||||||
bail!("read more than {} key bytes from stdin", blake3::KEY_LEN)
|
bail!("read more than {} key bytes from stdin", blake3::KEY_LEN)
|
||||||
} else {
|
} else {
|
||||||
Ok(bytes[..blake3::KEY_LEN].try_into().unwrap())
|
Ok(bytes[..blake3::KEY_LEN].try_into().unwrap())
|
||||||
|
|
|
@ -113,6 +113,15 @@ fn test_keyed() {
|
||||||
.read()
|
.read()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(&*expected, &*output);
|
assert_eq!(&*expected, &*output);
|
||||||
|
|
||||||
|
// Make sure that keys of the wrong length lead to errors.
|
||||||
|
for bad_length in [0, 1, blake3::KEY_LEN - 1, blake3::KEY_LEN + 1] {
|
||||||
|
dbg!(bad_length);
|
||||||
|
cmd!(b3sum_exe(), "--keyed", f.path())
|
||||||
|
.stdin_bytes(vec![0; bad_length])
|
||||||
|
.read()
|
||||||
|
.expect_err("a bad length key should fail");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Reference in New Issue