@@ -84,7 +84,7 @@ mod std_only {
84
84
85
85
impl < C : Context > Secp256k1 < C > {
86
86
fn gen_new ( ) -> Secp256k1 < C > {
87
- let buf = vec ! [ 0u8 ; Self :: preallocate_size ( ) ] . into_boxed_slice ( ) ;
87
+ let buf = vec ! [ 0u8 ; Self :: preallocate_size_gen ( ) ] . into_boxed_slice ( ) ;
88
88
let ptr = Box :: into_raw ( buf) ;
89
89
Secp256k1 {
90
90
ctx : unsafe { ffi:: secp256k1_context_preallocated_create ( ptr as * mut c_void , C :: FLAGS ) } ,
@@ -170,14 +170,14 @@ unsafe impl<'buf> Context for AllPreallocated<'buf> {
170
170
171
171
impl < ' buf , C : Context + ' buf > Secp256k1 < C > {
172
172
fn preallocated_gen_new ( buf : & ' buf mut [ u8 ] ) -> Result < Secp256k1 < C > , Error > {
173
- if buf. len ( ) < Self :: preallocate_size ( ) {
173
+ if buf. len ( ) < Self :: preallocate_size_gen ( ) {
174
174
return Err ( Error :: NotEnoughMemory ) ;
175
175
}
176
176
Ok ( Secp256k1 {
177
177
ctx : unsafe {
178
178
ffi:: secp256k1_context_preallocated_create (
179
179
buf. as_mut_ptr ( ) as * mut c_void ,
180
- AllPreallocated :: FLAGS )
180
+ C :: FLAGS )
181
181
} ,
182
182
phantom : PhantomData ,
183
183
buf : buf as * mut [ u8 ] ,
@@ -190,18 +190,34 @@ impl<'buf> Secp256k1<AllPreallocated<'buf>> {
190
190
pub fn preallocated_new ( buf : & ' buf mut [ u8 ] ) -> Result < Secp256k1 < AllPreallocated < ' buf > > , Error > {
191
191
Secp256k1 :: preallocated_gen_new ( buf)
192
192
}
193
+ /// Uses the ffi `secp256k1_context_preallocated_size` to check the memory size needed for a context
194
+ pub fn preallocate_size ( ) -> usize {
195
+ Self :: preallocate_size_gen ( )
196
+ }
193
197
}
194
198
195
199
impl < ' buf > Secp256k1 < SignOnlyPreallocated < ' buf > > {
196
200
/// Creates a new Secp256k1 context that can only be used for signing
197
- pub fn preallocated_new ( buf : & ' buf mut [ u8 ] ) -> Result < Secp256k1 < SignOnlyPreallocated < ' buf > > , Error > {
201
+ pub fn preallocated_signing_only ( buf : & ' buf mut [ u8 ] ) -> Result < Secp256k1 < SignOnlyPreallocated < ' buf > > , Error > {
198
202
Secp256k1 :: preallocated_gen_new ( buf)
199
203
}
204
+
205
+ /// Uses the ffi `secp256k1_context_preallocated_size` to check the memory size needed for the context
206
+ #[ inline]
207
+ pub fn preallocate_signing_size ( ) -> usize {
208
+ Self :: preallocate_size_gen ( )
209
+ }
200
210
}
201
211
202
212
impl < ' buf > Secp256k1 < VerifyOnlyPreallocated < ' buf > > {
203
213
/// Creates a new Secp256k1 context that can only be used for verification
204
- pub fn preallocated_new ( buf : & ' buf mut [ u8 ] ) -> Result < Secp256k1 < VerifyOnlyPreallocated < ' buf > > , Error > {
214
+ pub fn preallocated_verification_only ( buf : & ' buf mut [ u8 ] ) -> Result < Secp256k1 < VerifyOnlyPreallocated < ' buf > > , Error > {
205
215
Secp256k1 :: preallocated_gen_new ( buf)
206
216
}
217
+
218
+ /// Uses the ffi `secp256k1_context_preallocated_size` to check the memory size needed for the context
219
+ #[ inline]
220
+ pub fn preallocate_verification_size ( ) -> usize {
221
+ Self :: preallocate_size_gen ( )
222
+ }
207
223
}
0 commit comments