19
19
// Coding conventions
20
20
#![ deny( non_upper_case_globals, non_camel_case_types, non_snake_case, unused_mut) ]
21
21
22
- #![ allow( clippy:: missing_safety_doc) ]
23
-
24
22
#![ cfg_attr( all( not( test) , not( feature = "std" ) ) , no_std) ]
25
23
#![ cfg_attr( docsrs, feature( doc_cfg) ) ]
26
24
@@ -781,10 +779,25 @@ extern "C" {
781
779
///
782
780
/// Input `flags` control which parts of the context to initialize.
783
781
///
782
+ /// # Safety
783
+ ///
784
+ /// This function is unsafe because it calls unsafe functions however (assuming no bugs) no
785
+ /// undefined behavior is possible.
786
+ ///
784
787
/// # Returns
785
788
///
786
789
/// The newly created secp256k1 raw context.
790
+ #[ cfg( all( feature = "alloc" , not( rust_secp_no_symbol_renaming) ) ) ]
791
+ #[ cfg_attr( docsrs, doc( cfg( all( feature = "alloc" , not( rust_secp_no_symbol_renaming) ) ) ) ) ]
792
+ pub unsafe fn secp256k1_context_create ( flags : c_uint ) -> * mut Context {
793
+ rustsecp256k1_v0_6_1_context_create ( flags)
794
+ }
795
+
796
+ /// A reimplementation of the C function `secp256k1_context_create` in rust.
797
+ ///
798
+ /// See [`secp256k1_context_create`] for documentation and safety constraints.
787
799
#[ no_mangle]
800
+ #[ allow( clippy:: missing_safety_doc) ] // Documented above.
788
801
#[ cfg( all( feature = "alloc" , not( rust_secp_no_symbol_renaming) ) ) ]
789
802
#[ cfg_attr( docsrs, doc( cfg( all( feature = "alloc" , not( rust_secp_no_symbol_renaming) ) ) ) ) ]
790
803
pub unsafe extern "C" fn rustsecp256k1_v0_6_1_context_create ( flags : c_uint ) -> * mut Context {
@@ -805,19 +818,23 @@ pub unsafe extern "C" fn rustsecp256k1_v0_6_1_context_create(flags: c_uint) -> *
805
818
secp256k1_context_preallocated_create ( ptr, flags)
806
819
}
807
820
808
- #[ cfg( all( feature = "alloc" , not( rust_secp_no_symbol_renaming) ) ) ]
809
- #[ cfg_attr( docsrs, doc( cfg( all( feature = "alloc" , not( rust_secp_no_symbol_renaming) ) ) ) ) ]
810
- pub unsafe fn secp256k1_context_create ( flags : c_uint ) -> * mut Context {
811
- rustsecp256k1_v0_6_1_context_create ( flags)
812
- }
813
-
814
821
/// A reimplementation of the C function `secp256k1_context_destroy` in rust.
815
822
///
816
823
/// This function destroys and deallcates the context created by `secp256k1_context_create`.
817
824
///
818
825
/// The pointer shouldn't be used after passing to this function, consider it as passing it to `free()`.
819
826
///
827
+ /// # Safety
828
+ ///
829
+ /// `ctx` must be a valid pointer to a block of memory created using [`secp256k1_context_create`].
830
+ #[ cfg( all( feature = "alloc" , not( rust_secp_no_symbol_renaming) ) ) ]
831
+ #[ cfg_attr( docsrs, doc( cfg( all( feature = "alloc" , not( rust_secp_no_symbol_renaming) ) ) ) ) ]
832
+ pub unsafe fn secp256k1_context_destroy ( ctx : * mut Context ) {
833
+ rustsecp256k1_v0_6_1_context_destroy ( ctx)
834
+ }
835
+
820
836
#[ no_mangle]
837
+ #[ allow( clippy:: missing_safety_doc) ] // Documented above.
821
838
#[ cfg( all( feature = "alloc" , not( rust_secp_no_symbol_renaming) ) ) ]
822
839
#[ cfg_attr( docsrs, doc( cfg( all( feature = "alloc" , not( rust_secp_no_symbol_renaming) ) ) ) ) ]
823
840
pub unsafe extern "C" fn rustsecp256k1_v0_6_1_context_destroy ( ctx : * mut Context ) {
@@ -829,13 +846,6 @@ pub unsafe extern "C" fn rustsecp256k1_v0_6_1_context_destroy(ctx: *mut Context)
829
846
alloc:: dealloc ( ptr, layout) ;
830
847
}
831
848
832
- #[ cfg( all( feature = "alloc" , not( rust_secp_no_symbol_renaming) ) ) ]
833
- #[ cfg_attr( docsrs, doc( cfg( all( feature = "alloc" , not( rust_secp_no_symbol_renaming) ) ) ) ) ]
834
- pub unsafe fn secp256k1_context_destroy ( ctx : * mut Context ) {
835
- rustsecp256k1_v0_6_1_context_destroy ( ctx)
836
- }
837
-
838
-
839
849
/// **This function is an override for the C function, this is the an edited version of the original description:**
840
850
///
841
851
/// A callback function to be called when an illegal argument is passed to
@@ -854,6 +864,12 @@ pub unsafe fn secp256k1_context_destroy(ctx: *mut Context) {
854
864
///
855
865
/// See also secp256k1_default_error_callback_fn.
856
866
///
867
+ ///
868
+ /// # Safety
869
+ ///
870
+ /// `message` string should be a null terminated C string and, up to the first null byte, must be valid UTF8.
871
+ ///
872
+ /// For exact safety constraints see [`std::slice::from_raw_parts`] and [`std::str::from_utf8_unchecked`].
857
873
#[ no_mangle]
858
874
#[ cfg( not( rust_secp_no_symbol_renaming) ) ]
859
875
pub unsafe extern "C" fn rustsecp256k1_v0_6_1_default_illegal_callback_fn ( message : * const c_char , _data : * mut c_void ) {
@@ -877,6 +893,11 @@ pub unsafe extern "C" fn rustsecp256k1_v0_6_1_default_illegal_callback_fn(messag
877
893
///
878
894
/// See also secp256k1_default_illegal_callback_fn.
879
895
///
896
+ /// # Safety
897
+ ///
898
+ /// `message` string should be a null terminated C string and, up to the first null byte, must be valid UTF8.
899
+ ///
900
+ /// For exact safety constraints see [`std::slice::from_raw_parts`] and [`std::str::from_utf8_unchecked`].
880
901
#[ no_mangle]
881
902
#[ cfg( not( rust_secp_no_symbol_renaming) ) ]
882
903
pub unsafe extern "C" fn rustsecp256k1_v0_6_1_default_error_callback_fn ( message : * const c_char , _data : * mut c_void ) {
@@ -886,6 +907,11 @@ pub unsafe extern "C" fn rustsecp256k1_v0_6_1_default_error_callback_fn(message:
886
907
panic ! ( "[libsecp256k1] internal consistency check failed {}" , msg) ;
887
908
}
888
909
910
+ /// Returns the length of the `str_ptr` string.
911
+ ///
912
+ /// # Safety
913
+ ///
914
+ /// `str_ptr` must be valid pointer and point to a valid null terminated C string.
889
915
#[ cfg( not( rust_secp_no_symbol_renaming) ) ]
890
916
unsafe fn strlen ( mut str_ptr : * const c_char ) -> usize {
891
917
let mut ctr = 0 ;
0 commit comments