Skip to content

Commit b7e20c5

Browse files
committed
Changed all as_*ptr() to the safer CPtr trait
1 parent 66ab70f commit b7e20c5

File tree

6 files changed

+41
-41
lines changed

6 files changed

+41
-41
lines changed

src/context.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use core::marker::PhantomData;
2-
use ffi;
2+
use ffi::{self, CPtr};
33
use types::{c_uint, c_void};
44
use Error;
55
use Secp256k1;
@@ -181,7 +181,7 @@ impl<'buf, C: Context + 'buf> Secp256k1<C> {
181181
Ok(Secp256k1 {
182182
ctx: unsafe {
183183
ffi::secp256k1_context_preallocated_create(
184-
buf.as_mut_ptr() as *mut c_void,
184+
buf.as_mut_c_ptr() as *mut c_void,
185185
C::FLAGS)
186186
},
187187
phantom: PhantomData,

src/ecdh.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
use core::{ops, ptr};
2020

2121
use key::{SecretKey, PublicKey};
22-
use ffi;
22+
use ffi::{self, CPtr};
2323

2424
/// A tag used for recovering the public key from a compact signature
2525
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
@@ -34,8 +34,8 @@ impl SharedSecret {
3434
let res = ffi::secp256k1_ecdh(
3535
ffi::secp256k1_context_no_precomp,
3636
&mut ss,
37-
point.as_ptr(),
38-
scalar.as_ptr(),
37+
point.as_c_ptr(),
38+
scalar.as_c_ptr(),
3939
ffi::secp256k1_ecdh_hash_function_default,
4040
ptr::null_mut(),
4141
);

src/key.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ impl SecretKey {
117117
unsafe {
118118
while ffi::secp256k1_ec_seckey_verify(
119119
ffi::secp256k1_context_no_precomp,
120-
data.as_ptr(),
120+
data.as_c_ptr(),
121121
) == 0
122122
{
123123
data = random_32_bytes(rng);
@@ -135,7 +135,7 @@ impl SecretKey {
135135
unsafe {
136136
if ffi::secp256k1_ec_seckey_verify(
137137
ffi::secp256k1_context_no_precomp,
138-
data.as_ptr(),
138+
data.as_c_ptr(),
139139
) == 0
140140
{
141141
return Err(InvalidSecretKey);
@@ -162,8 +162,8 @@ impl SecretKey {
162162
unsafe {
163163
if ffi::secp256k1_ec_privkey_tweak_add(
164164
ffi::secp256k1_context_no_precomp,
165-
self.as_mut_ptr(),
166-
other.as_ptr(),
165+
self.as_mut_c_ptr(),
166+
other.as_c_ptr(),
167167
) != 1
168168
{
169169
Err(Error::InvalidTweak)
@@ -187,8 +187,8 @@ impl SecretKey {
187187
unsafe {
188188
if ffi::secp256k1_ec_privkey_tweak_mul(
189189
ffi::secp256k1_context_no_precomp,
190-
self.as_mut_ptr(),
191-
other.as_ptr(),
190+
self.as_mut_c_ptr(),
191+
other.as_c_ptr(),
192192
) != 1
193193
{
194194
Err(Error::InvalidTweak)
@@ -223,7 +223,7 @@ impl PublicKey {
223223
unsafe {
224224
// We can assume the return value because it's not possible to construct
225225
// an invalid `SecretKey` without transmute trickery or something
226-
let res = ffi::secp256k1_ec_pubkey_create(secp.ctx, &mut pk, sk.as_ptr());
226+
let res = ffi::secp256k1_ec_pubkey_create(secp.ctx, &mut pk, sk.as_c_ptr());
227227
debug_assert_eq!(res, 1);
228228
}
229229
PublicKey(pk)
@@ -237,7 +237,7 @@ impl PublicKey {
237237
if ffi::secp256k1_ec_pubkey_parse(
238238
ffi::secp256k1_context_no_precomp,
239239
&mut pk,
240-
data.as_ptr(),
240+
data.as_c_ptr(),
241241
data.len() as usize,
242242
) == 1
243243
{
@@ -259,9 +259,9 @@ impl PublicKey {
259259
let mut ret_len = constants::PUBLIC_KEY_SIZE as usize;
260260
let err = ffi::secp256k1_ec_pubkey_serialize(
261261
ffi::secp256k1_context_no_precomp,
262-
ret.as_mut_ptr(),
262+
ret.as_mut_c_ptr(),
263263
&mut ret_len,
264-
self.as_ptr(),
264+
self.as_c_ptr(),
265265
ffi::SECP256K1_SER_COMPRESSED,
266266
);
267267
debug_assert_eq!(err, 1);
@@ -278,9 +278,9 @@ impl PublicKey {
278278
let mut ret_len = constants::UNCOMPRESSED_PUBLIC_KEY_SIZE as usize;
279279
let err = ffi::secp256k1_ec_pubkey_serialize(
280280
ffi::secp256k1_context_no_precomp,
281-
ret.as_mut_ptr(),
281+
ret.as_mut_c_ptr(),
282282
&mut ret_len,
283-
self.as_ptr(),
283+
self.as_c_ptr(),
284284
ffi::SECP256K1_SER_UNCOMPRESSED,
285285
);
286286
debug_assert_eq!(err, 1);
@@ -303,7 +303,7 @@ impl PublicKey {
303303
}
304304
unsafe {
305305
if ffi::secp256k1_ec_pubkey_tweak_add(secp.ctx, &mut self.0 as *mut _,
306-
other.as_ptr()) == 1 {
306+
other.as_c_ptr()) == 1 {
307307
Ok(())
308308
} else {
309309
Err(Error::InvalidTweak)
@@ -325,7 +325,7 @@ impl PublicKey {
325325
}
326326
unsafe {
327327
if ffi::secp256k1_ec_pubkey_tweak_mul(secp.ctx, &mut self.0 as *mut _,
328-
other.as_ptr()) == 1 {
328+
other.as_c_ptr()) == 1 {
329329
Ok(())
330330
} else {
331331
Err(Error::InvalidTweak)
@@ -339,11 +339,11 @@ impl PublicKey {
339339
pub fn combine(&self, other: &PublicKey) -> Result<PublicKey, Error> {
340340
unsafe {
341341
let mut ret = ffi::PublicKey::new();
342-
let ptrs = [self.as_ptr(), other.as_ptr()];
342+
let ptrs = [self.as_c_ptr(), other.as_c_ptr()];
343343
if ffi::secp256k1_ec_pubkey_combine(
344344
ffi::secp256k1_context_no_precomp,
345345
&mut ret,
346-
ptrs.as_ptr(),
346+
ptrs.as_c_ptr(),
347347
2
348348
) == 1
349349
{

src/lib.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ impl Signature {
253253
if ffi::secp256k1_ecdsa_signature_parse_der(
254254
ffi::secp256k1_context_no_precomp,
255255
&mut ret,
256-
data.as_ptr(),
256+
data.as_c_ptr(),
257257
data.len() as usize,
258258
) == 1
259259
{
@@ -275,7 +275,7 @@ impl Signature {
275275
if ffi::secp256k1_ecdsa_signature_parse_compact(
276276
ffi::secp256k1_context_no_precomp,
277277
&mut ret,
278-
data.as_ptr(),
278+
data.as_c_ptr(),
279279
) == 1
280280
{
281281
Ok(Signature(ret))
@@ -295,7 +295,7 @@ impl Signature {
295295
if ffi::ecdsa_signature_parse_der_lax(
296296
ffi::secp256k1_context_no_precomp,
297297
&mut ret,
298-
data.as_ptr(),
298+
data.as_c_ptr(),
299299
data.len() as usize,
300300
) == 1
301301
{
@@ -329,8 +329,8 @@ impl Signature {
329329
// was already normalized. We don't care.
330330
ffi::secp256k1_ecdsa_signature_normalize(
331331
ffi::secp256k1_context_no_precomp,
332-
self.as_mut_ptr(),
333-
self.as_ptr(),
332+
self.as_mut_c_ptr(),
333+
self.as_c_ptr(),
334334
);
335335
}
336336
}
@@ -357,7 +357,7 @@ impl Signature {
357357
ffi::secp256k1_context_no_precomp,
358358
ret.get_data_mut_ptr(),
359359
&mut len,
360-
self.as_ptr(),
360+
self.as_c_ptr(),
361361
);
362362
debug_assert!(err == 1);
363363
ret.set_len(len);
@@ -372,8 +372,8 @@ impl Signature {
372372
unsafe {
373373
let err = ffi::secp256k1_ecdsa_signature_serialize_compact(
374374
ffi::secp256k1_context_no_precomp,
375-
ret.as_mut_ptr(),
376-
self.as_ptr(),
375+
ret.as_mut_c_ptr(),
376+
self.as_c_ptr(),
377377
);
378378
debug_assert!(err == 1);
379379
}
@@ -595,7 +595,7 @@ impl<C: Context> Secp256k1<C> {
595595
let mut seed = [0; 32];
596596
rng.fill_bytes(&mut seed);
597597
unsafe {
598-
let err = ffi::secp256k1_context_randomize(self.ctx, seed.as_ptr());
598+
let err = ffi::secp256k1_context_randomize(self.ctx, seed.as_c_ptr());
599599
// This function cannot fail; it has an error return for future-proofing.
600600
// We do not expose this error since it is impossible to hit, and we have
601601
// precedent for not exposing impossible errors (for example in
@@ -621,8 +621,8 @@ impl<C: Signing> Secp256k1<C> {
621621
unsafe {
622622
// We can assume the return value because it's not possible to construct
623623
// an invalid signature from a valid `Message` and `SecretKey`
624-
assert_eq!(ffi::secp256k1_ecdsa_sign(self.ctx, &mut ret, msg.as_ptr(),
625-
sk.as_ptr(), ffi::secp256k1_nonce_function_rfc6979,
624+
assert_eq!(ffi::secp256k1_ecdsa_sign(self.ctx, &mut ret, msg.as_c_ptr(),
625+
sk.as_c_ptr(), ffi::secp256k1_nonce_function_rfc6979,
626626
ptr::null()), 1);
627627
}
628628

@@ -652,7 +652,7 @@ impl<C: Verification> Secp256k1<C> {
652652
#[inline]
653653
pub fn verify(&self, msg: &Message, sig: &Signature, pk: &key::PublicKey) -> Result<(), Error> {
654654
unsafe {
655-
if ffi::secp256k1_ecdsa_verify(self.ctx, sig.as_ptr(), msg.as_ptr(), pk.as_ptr()) == 0 {
655+
if ffi::secp256k1_ecdsa_verify(self.ctx, sig.as_c_ptr(), msg.as_c_ptr(), pk.as_c_ptr()) == 0 {
656656
Err(Error::IncorrectSignature)
657657
} else {
658658
Ok(())

src/recovery/ffi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
1818
use core::mem;
1919
use types::*;
20-
use ffi::{Context, NonceFn, PublicKey, Signature};
20+
use ffi::{Context, NonceFn, PublicKey, Signature, CPtr};
2121

2222
/// Library-internal representation of a Secp256k1 signature + recovery ID
2323
#[repr(C)]

src/recovery/mod.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ impl RecoverableSignature {
6666
} else if ffi::secp256k1_ecdsa_recoverable_signature_parse_compact(
6767
super_ffi::secp256k1_context_no_precomp,
6868
&mut ret,
69-
data.as_ptr(),
69+
data.as_c_ptr(),
7070
recid.0,
7171
) == 1
7272
{
@@ -97,9 +97,9 @@ impl RecoverableSignature {
9797
unsafe {
9898
let err = ffi::secp256k1_ecdsa_recoverable_signature_serialize_compact(
9999
super_ffi::secp256k1_context_no_precomp,
100-
ret.as_mut_ptr(),
100+
ret.as_mut_c_ptr(),
101101
&mut recid,
102-
self.as_ptr(),
102+
self.as_c_ptr(),
103103
);
104104
assert!(err == 1);
105105
}
@@ -115,7 +115,7 @@ impl RecoverableSignature {
115115
let err = ffi::secp256k1_ecdsa_recoverable_signature_convert(
116116
super_ffi::secp256k1_context_no_precomp,
117117
&mut ret,
118-
self.as_ptr(),
118+
self.as_c_ptr(),
119119
);
120120
assert!(err == 1);
121121
}
@@ -157,8 +157,8 @@ impl<C: Signing> Secp256k1<C> {
157157
ffi::secp256k1_ecdsa_sign_recoverable(
158158
self.ctx,
159159
&mut ret,
160-
msg.as_ptr(),
161-
sk.as_ptr(),
160+
msg.as_c_ptr(),
161+
sk.as_c_ptr(),
162162
super_ffi::secp256k1_nonce_function_rfc6979,
163163
ptr::null()
164164
),
@@ -180,7 +180,7 @@ impl<C: Verification> Secp256k1<C> {
180180

181181
unsafe {
182182
if ffi::secp256k1_ecdsa_recover(self.ctx, &mut pk,
183-
sig.as_ptr(), msg.as_ptr()) != 1 {
183+
sig.as_c_ptr(), msg.as_c_ptr()) != 1 {
184184
return Err(Error::InvalidSignature);
185185
}
186186
};

0 commit comments

Comments
 (0)