mirror of
https://github.com/BLAKE3-team/BLAKE3
synced 2024-04-28 13:45:17 +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()
|
||||
.take(blake3::KEY_LEN as u64 + 1)
|
||||
.read_to_end(&mut bytes)?;
|
||||
if n < 32 {
|
||||
if n < blake3::KEY_LEN {
|
||||
bail!(
|
||||
"expected {} key bytes from stdin, found {}",
|
||||
blake3::KEY_LEN,
|
||||
n,
|
||||
)
|
||||
} else if n > 32 {
|
||||
} else if n > blake3::KEY_LEN {
|
||||
bail!("read more than {} key bytes from stdin", blake3::KEY_LEN)
|
||||
} else {
|
||||
Ok(bytes[..blake3::KEY_LEN].try_into().unwrap())
|
||||
|
|
|
@ -113,6 +113,15 @@ fn test_keyed() {
|
|||
.read()
|
||||
.unwrap();
|
||||
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]
|
||||
|
|
Loading…
Reference in New Issue