@@ -106,13 +106,32 @@ impl_array_newtype!(PublicKey, c_uchar, 64);
106
106
impl_raw_debug ! ( PublicKey ) ;
107
107
108
108
impl 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
+ }
112
128
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
116
135
}
117
136
}
118
137
@@ -129,13 +148,32 @@ impl_array_newtype!(Signature, c_uchar, 64);
129
148
impl_raw_debug ! ( Signature ) ;
130
149
131
150
impl 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
+ }
135
159
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
139
177
}
140
178
}
141
179
@@ -145,11 +183,33 @@ impl_array_newtype!(XOnlyPublicKey, c_uchar, 64);
145
183
impl_raw_debug ! ( XOnlyPublicKey ) ;
146
184
147
185
impl 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 {
151
203
XOnlyPublicKey ( data)
152
204
}
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
+ }
153
213
}
154
214
155
215
impl hash:: Hash for XOnlyPublicKey {
@@ -158,23 +218,39 @@ impl hash::Hash for XOnlyPublicKey {
158
218
}
159
219
}
160
220
161
- impl Default for XOnlyPublicKey {
162
- fn default ( ) -> Self {
163
- XOnlyPublicKey :: new ( )
164
- }
165
- }
166
-
167
221
#[ repr( C ) ]
168
222
pub struct KeyPair ( [ c_uchar ; 96 ] ) ;
169
223
impl_array_newtype ! ( KeyPair , c_uchar, 96 ) ;
170
224
impl_raw_debug ! ( KeyPair ) ;
171
225
172
226
impl 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 {
176
244
KeyPair ( data)
177
245
}
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
+ }
178
254
}
179
255
180
256
impl hash:: Hash for KeyPair {
@@ -183,12 +259,6 @@ impl hash::Hash for KeyPair {
183
259
}
184
260
}
185
261
186
- impl Default for KeyPair {
187
- fn default ( ) -> Self {
188
- KeyPair :: new ( )
189
- }
190
- }
191
-
192
262
#[ cfg( not( feature = "fuzztarget" ) ) ]
193
263
extern "C" {
194
264
/// Default ECDH hash function
@@ -591,7 +661,7 @@ impl<T> CPtr for [T] {
591
661
592
662
fn as_mut_c_ptr ( & mut self ) -> * mut Self :: Target {
593
663
if self . is_empty ( ) {
594
- ptr:: null :: < Self :: Target > ( ) as * mut _
664
+ ptr:: null_mut :: < Self :: Target > ( )
595
665
} else {
596
666
self . as_mut_ptr ( )
597
667
}
0 commit comments