@@ -50,18 +50,6 @@ pub unsafe extern "C" fn rust_sha256_finish(ctx: *mut *mut c_void, out: *mut c_u
5050 * ctx = core:: ptr:: null_mut ( ) ;
5151}
5252
53- /// Safety: ctx must be a pointer to a valid sha256 context produced by `rust_sha256_new()`, or a
54- /// pointer to NULL.
55- /// After this, the hasher is dropped and `ctx` is set to NULL and must not be used anymore.
56- #[ no_mangle]
57- pub unsafe extern "C" fn rust_sha256_free ( ctx : * mut * mut c_void ) {
58- if !( * ctx) . is_null ( ) {
59- #[ allow( clippy:: cast_ptr_alignment) ] // ctx is properly aligned, see `Box::into_raw`.
60- drop ( Box :: from_raw ( * ctx as * mut Sha256 ) ) ;
61- * ctx = core:: ptr:: null_mut ( ) ;
62- }
63- }
64-
6553/// Safety: data must be a valid buffer for `len` bytes. `out` must be 32 bytes long.
6654#[ no_mangle]
6755pub unsafe extern "C" fn rust_sha256 ( data : * const c_void , len : usize , out : * mut c_uchar ) {
@@ -110,30 +98,6 @@ mod tests {
11098 assert_eq ! ( result, & Sha256 :: digest( b"foo abc def xyz bar" ) [ ..] ) ;
11199 }
112100
113- #[ test]
114- fn test_free ( ) {
115- let mut ctx = rust_sha256_new ( ) ;
116- unsafe {
117- rust_sha256_free ( & mut ctx) ;
118- assert ! ( ctx. is_null( ) ) ;
119- rust_sha256_free ( & mut ctx) ;
120- }
121- }
122-
123- // Technically redundant to the other tests. Check that freeing always works.
124- #[ test]
125- fn test_free_after_use ( ) {
126- let mut ctx = rust_sha256_new ( ) ;
127- unsafe {
128- let mut result = [ 0u8 ; 32 ] ;
129- // This frees ctx.
130- rust_sha256_finish ( & mut ctx, result. as_mut_ptr ( ) ) ;
131- // ctx is NULL now.
132- rust_sha256_free ( & mut ctx) ;
133- assert ! ( ctx. is_null( ) ) ;
134- } ;
135- }
136-
137101 /// Test that input and output can be the same buffer.
138102 #[ test]
139103 fn test_overlapping ( ) {
0 commit comments