Skip to content

Commit 274424a

Browse files
authored
fix(rust/catalyst-types): Hash length check logic (#247)
* fix(catalyst-types): hash length check logic Signed-off-by: bkioshn <[email protected]> * fix(catalyst-types): format Signed-off-by: bkioshn <[email protected]> --------- Signed-off-by: bkioshn <[email protected]>
1 parent d1fc055 commit 274424a

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

rust/catalyst-types/src/hashes.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ impl<const BYTES: usize> TryFrom<&[u8]> for Blake2bHash<BYTES> {
102102
type Error = Blake2bHashError;
103103

104104
fn try_from(value: &[u8]) -> Result<Self, Self::Error> {
105-
if value.len() < BYTES {
105+
if value.len() != BYTES {
106106
return Err(Blake2bHashError::InvalidLength {
107107
expected: BYTES,
108108
actual: value.len(),
@@ -213,5 +213,16 @@ mod tests {
213213
} else {
214214
panic!("Expected InvalidLength error");
215215
}
216+
217+
let invalid_data = vec![0u8; 50];
218+
let result = Blake2b224Hash::try_from(&invalid_data);
219+
assert!(result.is_err());
220+
221+
if let Err(Blake2bHashError::InvalidLength { expected, actual }) = result {
222+
assert_eq!(expected, BLAKE_2B224_SIZE);
223+
assert_eq!(actual, invalid_data.len());
224+
} else {
225+
panic!("Expected InvalidLength error");
226+
}
216227
}
217228
}

0 commit comments

Comments
 (0)