@@ -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
}
@@ -395,14 +395,16 @@ impl<'de> serde::Deserialize<'de> for SecretKey {
395
395
impl PublicKey {
396
396
/// Obtains a raw const pointer suitable for use with FFI functions.
397
397
#[ inline]
398
+ #[ deprecated( since = "0.25.0" , note = "Use Self::as_c_ptr if you need to access the FFI layer" ) ]
398
399
pub fn as_ptr ( & self ) -> * const ffi:: PublicKey {
399
- & self . 0
400
+ self . as_c_ptr ( )
400
401
}
401
402
402
403
/// Obtains a raw mutable pointer suitable for use with FFI functions.
403
404
#[ inline]
405
+ #[ deprecated( since = "0.25.0" , note = "Use Self::as_mut_c_ptr if you need to access the FFI layer" ) ]
404
406
pub fn as_mut_ptr ( & mut self ) -> * mut ffi:: PublicKey {
405
- & mut self . 0
407
+ self . as_mut_c_ptr ( )
406
408
}
407
409
408
410
/// Creates a new public key from a [`SecretKey`].
@@ -479,7 +481,7 @@ impl PublicKey {
479
481
let ret = ffi:: secp256k1_keypair_pub (
480
482
ffi:: secp256k1_context_no_precomp,
481
483
& mut pk,
482
- keypair. as_ptr ( )
484
+ keypair. as_c_ptr ( )
483
485
) ;
484
486
debug_assert_eq ! ( ret, 1 ) ;
485
487
PublicKey ( pk)
@@ -666,7 +668,7 @@ impl PublicKey {
666
668
ffi:: secp256k1_context_no_precomp,
667
669
& mut xonly_pk,
668
670
& mut pk_parity,
669
- self . as_ptr ( ) ,
671
+ self . as_c_ptr ( ) ,
670
672
) ;
671
673
debug_assert_eq ! ( ret, 1 ) ;
672
674
let parity = Parity :: from_i32 ( pk_parity) . expect ( "should not panic, pk_parity is 0 or 1" ) ;
@@ -676,19 +678,26 @@ impl PublicKey {
676
678
}
677
679
}
678
680
681
+ /// This trait enables interaction with the FFI layer and even though it is part of the public API
682
+ /// normal users should never need to directly interact with FFI types.
679
683
impl CPtr for PublicKey {
680
684
type Target = ffi:: PublicKey ;
685
+
686
+ /// Obtains a const pointer suitable for use with FFI functions.
681
687
fn as_c_ptr ( & self ) -> * const Self :: Target {
682
- self . as_ptr ( )
688
+ & self . 0
683
689
}
684
690
691
+ /// Obtains a mutable pointer suitable for use with FFI functions.
685
692
fn as_mut_c_ptr ( & mut self ) -> * mut Self :: Target {
686
- self . as_mut_ptr ( )
693
+ & mut self . 0
687
694
}
688
695
}
689
696
690
697
691
- /// Creates a new public key from a FFI public key
698
+ /// Creates a new public key from a FFI public key.
699
+ ///
700
+ /// Note, normal users should never need to interact directly with FFI types.
692
701
impl From < ffi:: PublicKey > for PublicKey {
693
702
#[ inline]
694
703
fn from ( pk : ffi:: PublicKey ) -> PublicKey {
@@ -796,14 +805,16 @@ impl_display_secret!(KeyPair);
796
805
impl KeyPair {
797
806
/// Obtains a raw const pointer suitable for use with FFI functions.
798
807
#[ inline]
808
+ #[ deprecated( since = "0.25.0" , note = "Use Self::as_c_ptr if you need to access the FFI layer" ) ]
799
809
pub fn as_ptr ( & self ) -> * const ffi:: KeyPair {
800
- & self . 0
810
+ self . as_c_ptr ( )
801
811
}
802
812
803
813
/// Obtains a raw mutable pointer suitable for use with FFI functions.
804
814
#[ inline]
815
+ #[ deprecated( since = "0.25.0" , note = "Use Self::as_mut_c_ptr if you need to access the FFI layer" ) ]
805
816
pub fn as_mut_ptr ( & mut self ) -> * mut ffi:: KeyPair {
806
- & mut self . 0
817
+ self . as_mut_c_ptr ( )
807
818
}
808
819
809
820
/// Creates a [`KeyPair`] directly from a Secp256k1 secret key.
@@ -1090,6 +1101,17 @@ impl<'de> serde::Deserialize<'de> for KeyPair {
1090
1101
}
1091
1102
}
1092
1103
1104
+ impl CPtr for KeyPair {
1105
+ type Target = ffi:: KeyPair ;
1106
+ fn as_c_ptr ( & self ) -> * const Self :: Target {
1107
+ & self . 0
1108
+ }
1109
+
1110
+ fn as_mut_c_ptr ( & mut self ) -> * mut Self :: Target {
1111
+ & mut self . 0
1112
+ }
1113
+ }
1114
+
1093
1115
/// An x-only public key, used for verification of Schnorr signatures and serialized according to BIP-340.
1094
1116
///
1095
1117
/// # Serde support
@@ -1148,14 +1170,16 @@ impl str::FromStr for XOnlyPublicKey {
1148
1170
impl XOnlyPublicKey {
1149
1171
/// Obtains a raw const pointer suitable for use with FFI functions.
1150
1172
#[ inline]
1173
+ #[ deprecated( since = "0.25.0" , note = "Use Self::as_c_ptr if you need to access the FFI layer" ) ]
1151
1174
pub fn as_ptr ( & self ) -> * const ffi:: XOnlyPublicKey {
1152
- & self . 0
1175
+ self . as_c_ptr ( )
1153
1176
}
1154
1177
1155
1178
/// Obtains a raw mutable pointer suitable for use with FFI functions.
1156
1179
#[ inline]
1180
+ #[ deprecated( since = "0.25.0" , note = "Use Self::as_mut_c_ptr if you need to access the FFI layer" ) ]
1157
1181
pub fn as_mut_ptr ( & mut self ) -> * mut ffi:: XOnlyPublicKey {
1158
- & mut self . 0
1182
+ self . as_mut_c_ptr ( )
1159
1183
}
1160
1184
1161
1185
/// Returns the [`XOnlyPublicKey`] (and it's [`Parity`]) for `keypair`.
@@ -1168,7 +1192,7 @@ impl XOnlyPublicKey {
1168
1192
ffi:: secp256k1_context_no_precomp,
1169
1193
& mut xonly_pk,
1170
1194
& mut pk_parity,
1171
- keypair. as_ptr ( ) ,
1195
+ keypair. as_c_ptr ( ) ,
1172
1196
) ;
1173
1197
debug_assert_eq ! ( ret, 1 ) ;
1174
1198
let parity = Parity :: from_i32 ( pk_parity) . expect ( "should not panic, pk_parity is 0 or 1" ) ;
@@ -1496,11 +1520,11 @@ impl<'de> serde::Deserialize<'de> for Parity {
1496
1520
impl CPtr for XOnlyPublicKey {
1497
1521
type Target = ffi:: XOnlyPublicKey ;
1498
1522
fn as_c_ptr ( & self ) -> * const Self :: Target {
1499
- self . as_ptr ( )
1523
+ & self . 0
1500
1524
}
1501
1525
1502
1526
fn as_mut_c_ptr ( & mut self ) -> * mut Self :: Target {
1503
- self . as_mut_ptr ( )
1527
+ & mut self . 0
1504
1528
}
1505
1529
}
1506
1530
0 commit comments