mirror of
https://github.com/BLAKE3-team/BLAKE3
synced 2024-05-04 06:46:16 +02:00
add a test for blake3_hasher_init_derive_key_raw
This commit is contained in:
parent
44fd9efbc2
commit
ac1da75bb9
|
@ -64,6 +64,18 @@ impl Hasher {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn new_derive_key_raw(context: &[u8]) -> Self {
|
||||
let mut c_state = MaybeUninit::uninit();
|
||||
unsafe {
|
||||
ffi::blake3_hasher_init_derive_key_raw(
|
||||
c_state.as_mut_ptr(),
|
||||
context.as_ptr() as *const _,
|
||||
context.len(),
|
||||
);
|
||||
Self(c_state.assume_init())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn update(&mut self, input: &[u8]) {
|
||||
unsafe {
|
||||
ffi::blake3_hasher_update(&mut self.0, input.as_ptr() as *const c_void, input.len());
|
||||
|
@ -112,6 +124,11 @@ pub mod ffi {
|
|||
self_: *mut blake3_hasher,
|
||||
context: *const ::std::os::raw::c_char,
|
||||
);
|
||||
pub fn blake3_hasher_init_derive_key_raw(
|
||||
self_: *mut blake3_hasher,
|
||||
context: *const ::std::os::raw::c_void,
|
||||
context_len: usize,
|
||||
);
|
||||
pub fn blake3_hasher_update(
|
||||
self_: *mut blake3_hasher,
|
||||
input: *const ::std::os::raw::c_void,
|
||||
|
|
|
@ -383,11 +383,19 @@ fn test_compare_reference_impl() {
|
|||
let mut expected_out = [0; OUT];
|
||||
reference_hasher.finalize(&mut expected_out);
|
||||
|
||||
// the regular C string API
|
||||
let mut test_hasher = crate::Hasher::new_derive_key(context);
|
||||
test_hasher.update(input);
|
||||
let mut test_out = [0; OUT];
|
||||
test_hasher.finalize(&mut test_out);
|
||||
assert_eq!(test_out[..], expected_out[..]);
|
||||
|
||||
// the raw bytes API
|
||||
let mut test_hasher_raw = crate::Hasher::new_derive_key_raw(context.as_bytes());
|
||||
test_hasher_raw.update(input);
|
||||
let mut test_out_raw = [0; OUT];
|
||||
test_hasher_raw.finalize(&mut test_out_raw);
|
||||
assert_eq!(test_out_raw[..], expected_out[..]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue