Skip to content

Commit 4fb4b3c

Browse files
Rust wrapper: test BLAKE2 finalize() returns error for empty output buffer
1 parent ca362a4 commit 4fb4b3c

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

wrapper/rust/wolfssl-wolfcrypt/tests/test_blake2.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#[cfg(any(blake2b, blake2s))]
22
use wolfssl_wolfcrypt::blake2::*;
3+
#[cfg(any(blake2b, blake2s))]
4+
use wolfssl_wolfcrypt::sys;
35

46
#[test]
57
#[cfg(blake2b)]
@@ -50,6 +52,15 @@ fn test_blake2b() {
5052
}
5153
}
5254

55+
#[test]
56+
#[cfg(blake2b)]
57+
fn test_blake2b_finalize_empty_buffer() {
58+
let mut blake2b = BLAKE2b::new(64).expect("Error with new()");
59+
let mut hash: [u8; 0] = [];
60+
let rc = blake2b.finalize(&mut hash).expect_err("finalize() should fail");
61+
assert_eq!(rc, sys::wolfCrypt_ErrorCodes_BUFFER_E);
62+
}
63+
5364
#[test]
5465
#[cfg(blake2b_hmac)]
5566
fn test_blake2b_hmac() {
@@ -151,6 +162,15 @@ fn test_blake2s() {
151162
}
152163
}
153164

165+
#[test]
166+
#[cfg(blake2s)]
167+
fn test_blake2s_finalize_empty_buffer() {
168+
let mut blake2s = BLAKE2s::new(32).expect("Error with new()");
169+
let mut hash: [u8; 0] = [];
170+
let rc = blake2s.finalize(&mut hash).expect_err("finalize() should fail");
171+
assert_eq!(rc, sys::wolfCrypt_ErrorCodes_BUFFER_E);
172+
}
173+
154174
#[test]
155175
#[cfg(blake2s_hmac)]
156176
fn test_blake2s_hmac() {

0 commit comments

Comments
 (0)