@@ -221,7 +221,7 @@ impl SecretKey {
221
221
let ret = ffi:: secp256k1_keypair_sec (
222
222
ffi:: secp256k1_context_no_precomp,
223
223
sk. as_mut_c_ptr ( ) ,
224
- keypair. as_ptr ( )
224
+ keypair. as_c_ptr ( )
225
225
) ;
226
226
debug_assert_eq ! ( ret, 1 ) ;
227
227
}
@@ -423,14 +423,16 @@ impl<'de> serde::Deserialize<'de> for SecretKey {
423
423
impl PublicKey {
424
424
/// Obtains a raw const pointer suitable for use with FFI functions.
425
425
#[ inline]
426
+ #[ deprecated( since = "0.25.0" , note = "Use Self::as_c_ptr if you need to access the FFI layer" ) ]
426
427
pub fn as_ptr ( & self ) -> * const ffi:: PublicKey {
427
- & self . 0
428
+ self . as_c_ptr ( )
428
429
}
429
430
430
431
/// Obtains a raw mutable pointer suitable for use with FFI functions.
431
432
#[ inline]
433
+ #[ deprecated( since = "0.25.0" , note = "Use Self::as_mut_c_ptr if you need to access the FFI layer" ) ]
432
434
pub fn as_mut_ptr ( & mut self ) -> * mut ffi:: PublicKey {
433
- & mut self . 0
435
+ self . as_mut_c_ptr ( )
434
436
}
435
437
436
438
/// Creates a new public key from a [`SecretKey`].
@@ -507,7 +509,7 @@ impl PublicKey {
507
509
let ret = ffi:: secp256k1_keypair_pub (
508
510
ffi:: secp256k1_context_no_precomp,
509
511
& mut pk,
510
- keypair. as_ptr ( )
512
+ keypair. as_c_ptr ( )
511
513
) ;
512
514
debug_assert_eq ! ( ret, 1 ) ;
513
515
PublicKey ( pk)
@@ -733,7 +735,7 @@ impl PublicKey {
733
735
ffi:: secp256k1_context_no_precomp,
734
736
& mut xonly_pk,
735
737
& mut pk_parity,
736
- self . as_ptr ( ) ,
738
+ self . as_c_ptr ( ) ,
737
739
) ;
738
740
debug_assert_eq ! ( ret, 1 ) ;
739
741
let parity = Parity :: from_i32 ( pk_parity) . expect ( "should not panic, pk_parity is 0 or 1" ) ;
@@ -743,19 +745,26 @@ impl PublicKey {
743
745
}
744
746
}
745
747
748
+ /// This trait enables interaction with the FFI layer and even though it is part of the public API
749
+ /// normal users should never need to directly interact with FFI types.
746
750
impl CPtr for PublicKey {
747
751
type Target = ffi:: PublicKey ;
752
+
753
+ /// Obtains a const pointer suitable for use with FFI functions.
748
754
fn as_c_ptr ( & self ) -> * const Self :: Target {
749
- self . as_ptr ( )
755
+ & self . 0
750
756
}
751
757
758
+ /// Obtains a mutable pointer suitable for use with FFI functions.
752
759
fn as_mut_c_ptr ( & mut self ) -> * mut Self :: Target {
753
- self . as_mut_ptr ( )
760
+ & mut self . 0
754
761
}
755
762
}
756
763
757
764
758
- /// Creates a new public key from a FFI public key
765
+ /// Creates a new public key from a FFI public key.
766
+ ///
767
+ /// Note, normal users should never need to interact directly with FFI types.
759
768
impl From < ffi:: PublicKey > for PublicKey {
760
769
#[ inline]
761
770
fn from ( pk : ffi:: PublicKey ) -> PublicKey {
@@ -845,14 +854,16 @@ impl_display_secret!(KeyPair);
845
854
impl KeyPair {
846
855
/// Obtains a raw const pointer suitable for use with FFI functions.
847
856
#[ inline]
857
+ #[ deprecated( since = "0.25.0" , note = "Use Self::as_c_ptr if you need to access the FFI layer" ) ]
848
858
pub fn as_ptr ( & self ) -> * const ffi:: KeyPair {
849
- & self . 0
859
+ self . as_c_ptr ( )
850
860
}
851
861
852
862
/// Obtains a raw mutable pointer suitable for use with FFI functions.
853
863
#[ inline]
864
+ #[ deprecated( since = "0.25.0" , note = "Use Self::as_mut_c_ptr if you need to access the FFI layer" ) ]
854
865
pub fn as_mut_ptr ( & mut self ) -> * mut ffi:: KeyPair {
855
- & mut self . 0
866
+ self . as_mut_c_ptr ( )
856
867
}
857
868
858
869
/// Creates a [`KeyPair`] directly from a Secp256k1 secret key.
@@ -1152,6 +1163,17 @@ impl<'de> serde::Deserialize<'de> for KeyPair {
1152
1163
}
1153
1164
}
1154
1165
1166
+ impl CPtr for KeyPair {
1167
+ type Target = ffi:: KeyPair ;
1168
+ fn as_c_ptr ( & self ) -> * const Self :: Target {
1169
+ & self . 0
1170
+ }
1171
+
1172
+ fn as_mut_c_ptr ( & mut self ) -> * mut Self :: Target {
1173
+ & mut self . 0
1174
+ }
1175
+ }
1176
+
1155
1177
/// An x-only public key, used for verification of Schnorr signatures and serialized according to BIP-340.
1156
1178
///
1157
1179
/// # Serde support
@@ -1210,14 +1232,16 @@ impl str::FromStr for XOnlyPublicKey {
1210
1232
impl XOnlyPublicKey {
1211
1233
/// Obtains a raw const pointer suitable for use with FFI functions.
1212
1234
#[ inline]
1235
+ #[ deprecated( since = "0.25.0" , note = "Use Self::as_c_ptr if you need to access the FFI layer" ) ]
1213
1236
pub fn as_ptr ( & self ) -> * const ffi:: XOnlyPublicKey {
1214
- & self . 0
1237
+ self . as_c_ptr ( )
1215
1238
}
1216
1239
1217
1240
/// Obtains a raw mutable pointer suitable for use with FFI functions.
1218
1241
#[ inline]
1242
+ #[ deprecated( since = "0.25.0" , note = "Use Self::as_mut_c_ptr if you need to access the FFI layer" ) ]
1219
1243
pub fn as_mut_ptr ( & mut self ) -> * mut ffi:: XOnlyPublicKey {
1220
- & mut self . 0
1244
+ self . as_mut_c_ptr ( )
1221
1245
}
1222
1246
1223
1247
/// Returns the [`XOnlyPublicKey`] (and it's [`Parity`]) for `keypair`.
@@ -1230,7 +1254,7 @@ impl XOnlyPublicKey {
1230
1254
ffi:: secp256k1_context_no_precomp,
1231
1255
& mut xonly_pk,
1232
1256
& mut pk_parity,
1233
- keypair. as_ptr ( ) ,
1257
+ keypair. as_c_ptr ( ) ,
1234
1258
) ;
1235
1259
debug_assert_eq ! ( ret, 1 ) ;
1236
1260
let parity = Parity :: from_i32 ( pk_parity) . expect ( "should not panic, pk_parity is 0 or 1" ) ;
@@ -1570,11 +1594,11 @@ impl<'de> serde::Deserialize<'de> for Parity {
1570
1594
impl CPtr for XOnlyPublicKey {
1571
1595
type Target = ffi:: XOnlyPublicKey ;
1572
1596
fn as_c_ptr ( & self ) -> * const Self :: Target {
1573
- self . as_ptr ( )
1597
+ & self . 0
1574
1598
}
1575
1599
1576
1600
fn as_mut_c_ptr ( & mut self ) -> * mut Self :: Target {
1577
- self . as_mut_ptr ( )
1601
+ & mut self . 0
1578
1602
}
1579
1603
}
1580
1604
0 commit comments