@@ -351,15 +351,22 @@ impl<'buf> Secp256k1<AllPreallocated<'buf>> {
351
351
352
352
/// Creates a context from a raw context.
353
353
///
354
+ /// The returned [`core::mem::ManuallyDrop`] context will never deallocate the memory pointed to
355
+ /// by `raw_ctx` nor destroy the context. This may lead to memory leaks. `ManuallyDrop::drop`
356
+ /// (or [`core::ptr::drop_in_place`]) will only destroy the context; the caller is required to
357
+ /// free the memory.
358
+ ///
354
359
/// # Safety
355
- /// This is highly unsafe, due to the number of conditions that aren't checked.
356
- /// * `raw_ctx` needs to be a valid Secp256k1 context pointer.
357
- /// that was generated by *exactly* the same code/version of the libsecp256k1 used here.
358
- /// * The capabilities (All/SignOnly/VerifyOnly) of the context *must* match the flags passed to libsecp256k1
359
- /// when generating the context.
360
- /// * The user must handle the freeing of the context(using the correct functions) by himself.
361
- /// * Violating these may lead to Undefined Behavior.
362
360
///
361
+ /// This is highly unsafe due to a number of conditions that aren't checked, specifically:
362
+ ///
363
+ /// * `raw_ctx` must be a valid pointer (live, aligned...) to memory that was initialized by
364
+ /// `secp256k1_context_preallocated_create` (either called directly or from this library by
365
+ /// one of the context creation methods - all of which call it internally).
366
+ /// * The version of `libsecp256k1` used to create `raw_ctx` must be the same as the version
367
+ /// used by this library.
368
+ /// * The lifetime of the `raw_ctx` pointer must outlive `'buf`.
369
+ /// * `raw_ctx` must point to writable memory (cannot be `ffi::secp256k1_context_no_precomp`).
363
370
pub unsafe fn from_raw_all (
364
371
raw_ctx : NonNull < ffi:: Context > ,
365
372
) -> ManuallyDrop < Secp256k1 < AllPreallocated < ' buf > > > {
@@ -379,18 +386,11 @@ impl<'buf> Secp256k1<SignOnlyPreallocated<'buf>> {
379
386
#[ inline]
380
387
pub fn preallocate_signing_size ( ) -> usize { Self :: preallocate_size_gen ( ) }
381
388
382
- /// Creates a context from a raw context.
389
+ /// Creates a context from a raw context that can only be used for signing .
383
390
///
384
391
/// # Safety
385
392
///
386
- /// This is highly unsafe, due to the number of conditions that aren't checked.
387
- /// * `raw_ctx` needs to be a valid Secp256k1 context pointer.
388
- /// that was generated by *exactly* the same code/version of the libsecp256k1 used here.
389
- /// * The capabilities (All/SignOnly/VerifyOnly) of the context *must* match the flags passed to libsecp256k1
390
- /// when generating the context.
391
- /// * The user must handle the freeing of the context(using the correct functions) by himself.
392
- /// * This list *is not* exhaustive, and any violation may lead to Undefined Behavior.
393
- ///
393
+ /// Please see [`Secp256k1::from_raw_all`] for full documentation and safety requirements.
394
394
pub unsafe fn from_raw_signing_only (
395
395
raw_ctx : NonNull < ffi:: Context > ,
396
396
) -> ManuallyDrop < Secp256k1 < SignOnlyPreallocated < ' buf > > > {
@@ -410,18 +410,11 @@ impl<'buf> Secp256k1<VerifyOnlyPreallocated<'buf>> {
410
410
#[ inline]
411
411
pub fn preallocate_verification_size ( ) -> usize { Self :: preallocate_size_gen ( ) }
412
412
413
- /// Creates a context from a raw context.
413
+ /// Creates a context from a raw context that can only be used for verification .
414
414
///
415
415
/// # Safety
416
416
///
417
- /// This is highly unsafe, due to the number of conditions that aren't checked.
418
- /// * `raw_ctx` needs to be a valid Secp256k1 context pointer.
419
- /// that was generated by *exactly* the same code/version of the libsecp256k1 used here.
420
- /// * The capabilities (All/SignOnly/VerifyOnly) of the context *must* match the flags passed to libsecp256k1
421
- /// when generating the context.
422
- /// * The user must handle the freeing of the context(using the correct functions) by himself.
423
- /// * This list *is not* exhaustive, and any violation may lead to Undefined Behavior.
424
- ///
417
+ /// Please see [`Secp256k1::from_raw_all`] for full documentation and safety requirements.
425
418
pub unsafe fn from_raw_verification_only (
426
419
raw_ctx : NonNull < ffi:: Context > ,
427
420
) -> ManuallyDrop < Secp256k1 < VerifyOnlyPreallocated < ' buf > > > {
0 commit comments