check mask length

This commit is contained in:
Dmitry Belyaev 2022-08-28 01:07:34 +03:00
parent d5910d8350
commit 3cfa470f43
Signed by: b4tman
GPG Key ID: 41A00BF15EA7E5F3

View File

@ -73,6 +73,9 @@ impl FromStr for BytesPattern {
impl From<(Vec<u8>, Vec<bool>)> for BytesPattern {
fn from(x: (Vec<u8>, Vec<bool>)) -> Self {
if x.0.len() != x.1.len() {
panic!("mask length mismatch");
}
let mut s = Self {
bytes: x.0,
mask: x.1,
@ -255,4 +258,10 @@ mod tests {
];
assert_eq!(mask, pattern.mask);
}
#[test]
#[should_panic(expected = "mask length mismatch")]
fn pattern_from_tupple_wrong_mask_length() {
let _pattern = BytesPattern::from((vec![1u8, 2u8, 3u8], vec![true, false]));
}
}