Rust wrapper: test BLAKE2 finalize() returns error for empty output buffer

pull/10205/head
Josh Holtrop 2026-04-14 10:40:53 -04:00
parent ca362a4e8f
commit 4fb4b3c0c8
1 changed files with 20 additions and 0 deletions

View File

@ -1,5 +1,7 @@
#[cfg(any(blake2b, blake2s))]
use wolfssl_wolfcrypt::blake2::*;
#[cfg(any(blake2b, blake2s))]
use wolfssl_wolfcrypt::sys;
#[test]
#[cfg(blake2b)]
@ -50,6 +52,15 @@ fn test_blake2b() {
}
}
#[test]
#[cfg(blake2b)]
fn test_blake2b_finalize_empty_buffer() {
let mut blake2b = BLAKE2b::new(64).expect("Error with new()");
let mut hash: [u8; 0] = [];
let rc = blake2b.finalize(&mut hash).expect_err("finalize() should fail");
assert_eq!(rc, sys::wolfCrypt_ErrorCodes_BUFFER_E);
}
#[test]
#[cfg(blake2b_hmac)]
fn test_blake2b_hmac() {
@ -151,6 +162,15 @@ fn test_blake2s() {
}
}
#[test]
#[cfg(blake2s)]
fn test_blake2s_finalize_empty_buffer() {
let mut blake2s = BLAKE2s::new(32).expect("Error with new()");
let mut hash: [u8; 0] = [];
let rc = blake2s.finalize(&mut hash).expect_err("finalize() should fail");
assert_eq!(rc, sys::wolfCrypt_ErrorCodes_BUFFER_E);
}
#[test]
#[cfg(blake2s_hmac)]
fn test_blake2s_hmac() {