diff options
| author | Jack O'Connor <[email protected]> | 2020-09-10 16:47:56 -0400 |
|---|---|---|
| committer | Jack O'Connor <[email protected]> | 2020-09-10 16:52:14 -0400 |
| commit | ac1da75bb9c65a0fcfe370b6e7ec8b1b7474786d (patch) | |
| tree | ad1eb6a4576325f0e2eeb64da083cac89aa5ce67 | |
| parent | 44fd9efbc26eecad533a7507af3d6f921ce7656c (diff) | |
add a test for blake3_hasher_init_derive_key_raw
| -rw-r--r-- | c/blake3_c_rust_bindings/src/lib.rs | 17 | ||||
| -rw-r--r-- | c/blake3_c_rust_bindings/src/test.rs | 8 |
2 files changed, 25 insertions, 0 deletions
diff --git a/c/blake3_c_rust_bindings/src/lib.rs b/c/blake3_c_rust_bindings/src/lib.rs index a695f01..f18fe12 100644 --- a/c/blake3_c_rust_bindings/src/lib.rs +++ b/c/blake3_c_rust_bindings/src/lib.rs @@ -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, diff --git a/c/blake3_c_rust_bindings/src/test.rs b/c/blake3_c_rust_bindings/src/test.rs index 62a7ee1..f824ceb 100644 --- a/c/blake3_c_rust_bindings/src/test.rs +++ b/c/blake3_c_rust_bindings/src/test.rs @@ -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[..]); } } } |
