@@ -106,13 +106,32 @@ impl_array_newtype!(PublicKey, c_uchar, 64);
106106impl_raw_debug ! ( PublicKey ) ;
107107
108108impl PublicKey {
109- /// Create a new (zeroed) public key usable for the FFI interface
110- pub fn new ( ) -> PublicKey { PublicKey ( [ 0 ; 64 ] ) }
111- }
109+ /// Creates an "uninitialized" FFI public key which is zeroed out
110+ ///
111+ /// If you pass this to any FFI functions, except as an out-pointer,
112+ /// the result is likely to be an assertation failure and process
113+ /// termination.
114+ pub unsafe fn new ( ) -> Self {
115+ Self :: from_array_unchecked ( [ 0 ; 64 ] )
116+ }
117+
118+ /// Create a new public key usable for the FFI interface from raw bytes
119+ ///
120+ /// Does not check the validity of the underlying representation. If it is
121+ /// invalid the result may be assertation failures (and process aborts) from
122+ /// the underlying library. You should not use this method except with data
123+ /// that you obtained from the FFI interface of the same version of this
124+ /// library.
125+ pub unsafe fn from_array_unchecked ( data : [ c_uchar ; 64 ] ) -> Self {
126+ PublicKey ( data)
127+ }
112128
113- impl Default for PublicKey {
114- fn default ( ) -> Self {
115- PublicKey :: new ( )
129+ /// Returns the underlying FFI opaque representation of the public key
130+ ///
131+ /// You should not use this unless you really know what you are doing. It is
132+ /// essentially only useful for extending the FFI interface itself.
133+ pub fn underlying_bytes ( self ) -> [ c_uchar ; 64 ] {
134+ self . 0
116135 }
117136}
118137
@@ -129,13 +148,32 @@ impl_array_newtype!(Signature, c_uchar, 64);
129148impl_raw_debug ! ( Signature ) ;
130149
131150impl Signature {
132- /// Create a new (zeroed) signature usable for the FFI interface
133- pub fn new ( ) -> Signature { Signature ( [ 0 ; 64 ] ) }
134- }
151+ /// Creates an "uninitialized" FFI signature which is zeroed out
152+ ///
153+ /// If you pass this to any FFI functions, except as an out-pointer,
154+ /// the result is likely to be an assertation failure and process
155+ /// termination.
156+ pub unsafe fn new ( ) -> Self {
157+ Self :: from_array_unchecked ( [ 0 ; 64 ] )
158+ }
135159
136- impl Default for Signature {
137- fn default ( ) -> Self {
138- Signature :: new ( )
160+ /// Create a new signature usable for the FFI interface from raw bytes
161+ ///
162+ /// Does not check the validity of the underlying representation. If it is
163+ /// invalid the result may be assertation failures (and process aborts) from
164+ /// the underlying library. You should not use this method except with data
165+ /// that you obtained from the FFI interface of the same version of this
166+ /// library.
167+ pub unsafe fn from_array_unchecked ( data : [ c_uchar ; 64 ] ) -> Self {
168+ Signature ( data)
169+ }
170+
171+ /// Returns the underlying FFI opaque representation of the signature
172+ ///
173+ /// You should not use this unless you really know what you are doing. It is
174+ /// essentially only useful for extending the FFI interface itself.
175+ pub fn underlying_bytes ( self ) -> [ c_uchar ; 64 ] {
176+ self . 0
139177 }
140178}
141179
@@ -145,11 +183,33 @@ impl_array_newtype!(XOnlyPublicKey, c_uchar, 64);
145183impl_raw_debug ! ( XOnlyPublicKey ) ;
146184
147185impl XOnlyPublicKey {
148- /// Create a new (zeroed) x-only public key usable for the FFI interface
149- pub fn new ( ) -> XOnlyPublicKey { XOnlyPublicKey ( [ 0 ; 64 ] ) }
150- pub fn from_array ( data : [ c_uchar ; 64 ] ) -> XOnlyPublicKey {
186+ /// Creates an "uninitialized" FFI x-only public key which is zeroed out
187+ ///
188+ /// If you pass this to any FFI functions, except as an out-pointer,
189+ /// the result is likely to be an assertation failure and process
190+ /// termination.
191+ pub unsafe fn new ( ) -> Self {
192+ Self :: from_array_unchecked ( [ 0 ; 64 ] )
193+ }
194+
195+ /// Create a new x-only public key usable for the FFI interface from raw bytes
196+ ///
197+ /// Does not check the validity of the underlying representation. If it is
198+ /// invalid the result may be assertation failures (and process aborts) from
199+ /// the underlying library. You should not use this method except with data
200+ /// that you obtained from the FFI interface of the same version of this
201+ /// library.
202+ pub unsafe fn from_array_unchecked ( data : [ c_uchar ; 64 ] ) -> Self {
151203 XOnlyPublicKey ( data)
152204 }
205+
206+ /// Returns the underlying FFI opaque representation of the x-only public key
207+ ///
208+ /// You should not use this unless you really know what you are doing. It is
209+ /// essentially only useful for extending the FFI interface itself.
210+ pub fn underlying_bytes ( self ) -> [ c_uchar ; 64 ] {
211+ self . 0
212+ }
153213}
154214
155215impl hash:: Hash for XOnlyPublicKey {
@@ -158,23 +218,39 @@ impl hash::Hash for XOnlyPublicKey {
158218 }
159219}
160220
161- impl Default for XOnlyPublicKey {
162- fn default ( ) -> Self {
163- XOnlyPublicKey :: new ( )
164- }
165- }
166-
167221#[ repr( C ) ]
168222pub struct KeyPair ( [ c_uchar ; 96 ] ) ;
169223impl_array_newtype ! ( KeyPair , c_uchar, 96 ) ;
170224impl_raw_debug ! ( KeyPair ) ;
171225
172226impl KeyPair {
173- /// Create a new (zeroed) key pair usable for the FFI interface
174- pub fn new ( ) -> KeyPair { KeyPair ( [ 0 ; 96 ] ) }
175- pub fn from_array ( data : [ c_uchar ; 96 ] ) -> KeyPair {
227+ /// Creates an "uninitialized" FFI keypair which is zeroed out
228+ ///
229+ /// If you pass this to any FFI functions, except as an out-pointer,
230+ /// the result is likely to be an assertation failure and process
231+ /// termination.
232+ pub unsafe fn new ( ) -> Self {
233+ Self :: from_array_unchecked ( [ 0 ; 96 ] )
234+ }
235+
236+ /// Create a new keypair usable for the FFI interface from raw bytes
237+ ///
238+ /// Does not check the validity of the underlying representation. If it is
239+ /// invalid the result may be assertation failures (and process aborts) from
240+ /// the underlying library. You should not use this method except with data
241+ /// that you obtained from the FFI interface of the same version of this
242+ /// library.
243+ pub unsafe fn from_array_unchecked ( data : [ c_uchar ; 96 ] ) -> Self {
176244 KeyPair ( data)
177245 }
246+
247+ /// Returns the underlying FFI opaque representation of the x-only public key
248+ ///
249+ /// You should not use this unless you really know what you are doing. It is
250+ /// essentially only useful for extending the FFI interface itself.
251+ pub fn underlying_bytes ( self ) -> [ c_uchar ; 96 ] {
252+ self . 0
253+ }
178254}
179255
180256impl hash:: Hash for KeyPair {
@@ -183,12 +259,6 @@ impl hash::Hash for KeyPair {
183259 }
184260}
185261
186- impl Default for KeyPair {
187- fn default ( ) -> Self {
188- KeyPair :: new ( )
189- }
190- }
191-
192262#[ cfg( not( feature = "fuzztarget" ) ) ]
193263extern "C" {
194264 /// Default ECDH hash function
@@ -591,7 +661,7 @@ impl<T> CPtr for [T] {
591661
592662 fn as_mut_c_ptr ( & mut self ) -> * mut Self :: Target {
593663 if self . is_empty ( ) {
594- ptr:: null :: < Self :: Target > ( ) as * mut _
664+ ptr:: null_mut :: < Self :: Target > ( )
595665 } else {
596666 self . as_mut_ptr ( )
597667 }
0 commit comments