Skip to content

Commit 846faae

Browse files
committed
Exposed generic functions to create the Context
1 parent 49f0cc1 commit 846faae

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

src/context.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ mod std_only {
8686
}
8787

8888
impl<C: Context> Secp256k1<C> {
89-
fn gen_new() -> Secp256k1<C> {
89+
/// Let's you create a context in a generic manner(sign/verify/all)
90+
pub fn gen_new() -> Secp256k1<C> {
9091
let buf = vec![0u8; Self::preallocate_size_gen()].into_boxed_slice();
9192
let ptr = Box::into_raw(buf);
9293
Secp256k1 {
@@ -148,8 +149,8 @@ unsafe impl<'buf> Context for SignOnlyPreallocated<'buf> {
148149
const FLAGS: c_uint = ffi::SECP256K1_START_SIGN;
149150
const DESCRIPTION: &'static str = "signing only";
150151

151-
fn deallocate(ptr: *mut [u8]) {
152-
let _ = ptr;
152+
fn deallocate(_ptr: *mut [u8]) {
153+
// Allocated by the user
153154
}
154155
}
155156

@@ -158,7 +159,7 @@ unsafe impl<'buf> Context for VerifyOnlyPreallocated<'buf> {
158159
const DESCRIPTION: &'static str = "verification only";
159160

160161
fn deallocate(ptr: *mut [u8]) {
161-
let _ = ptr;
162+
// Allocated by the user
162163
}
163164
}
164165

@@ -167,12 +168,13 @@ unsafe impl<'buf> Context for AllPreallocated<'buf> {
167168
const DESCRIPTION: &'static str = "all capabilities";
168169

169170
fn deallocate(ptr: *mut [u8]) {
170-
let _ = ptr;
171+
// Allocated by the user
171172
}
172173
}
173174

174175
impl<'buf, C: Context + 'buf> Secp256k1<C> {
175-
fn preallocated_gen_new(buf: &'buf mut [u8]) -> Result<Secp256k1<C>, Error> {
176+
/// Let's you create a context with preallocated buffer in a generic manner(sign/verify/all)
177+
pub fn preallocated_gen_new(buf: &'buf mut [u8]) -> Result<Secp256k1<C>, Error> {
176178
if buf.len() < Self::preallocate_size_gen() {
177179
return Err(Error::NotEnoughMemory);
178180
}

src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -570,8 +570,8 @@ impl<C: Context> Secp256k1<C> {
570570
&self.ctx
571571
}
572572

573-
/// Uses the ffi `secp256k1_context_preallocated_size` to check the memory size needed for a context
574-
pub(crate) fn preallocate_size_gen() -> usize {
573+
/// Returns the required memory for a preallocated context buffer in a generic manner(sign/verify/all)
574+
pub fn preallocate_size_gen() -> usize {
575575
unsafe { ffi::secp256k1_context_preallocated_size(C::FLAGS) }
576576
}
577577

0 commit comments

Comments
 (0)