Skip to content

Commit 7e657a5

Browse files
change engine return types to integer
1 parent 0f67bc5 commit 7e657a5

File tree

1 file changed

+72
-73
lines changed

1 file changed

+72
-73
lines changed

openssl/src/engine.rs

+72-73
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use libc::strlen;
44
use openssl_macros::corresponds;
55
use std::ffi::{c_void, CString};
66

7-
struct Engine(*mut ffi::ENGINE);
7+
pub struct Engine(*mut ffi::ENGINE);
88

99
impl Engine {
1010
/// Creates a new Engine.
@@ -71,21 +71,19 @@ impl Engine {
7171
/// Adds the engine to OpenSSL's internal engine list.
7272
#[corresponds(ENGINE_add)]
7373
#[inline]
74-
pub fn add(&mut self) -> Result<(), ErrorStack> {
74+
pub fn add(&mut self) -> Result<i32, ErrorStack> {
7575
unsafe {
76-
cvt(ffi::ENGINE_add(self.as_ptr()))?;
76+
return cvt(ffi::ENGINE_add(self.as_ptr()));
7777
}
78-
Ok(())
7978
}
8079

8180
/// Removes the engine from OpenSSL's internal engine list.
8281
#[corresponds(ENGINE_remove)]
8382
#[inline]
84-
pub fn remove(&mut self) -> Result<(), ErrorStack> {
83+
pub fn remove(&mut self) -> Result<i32, ErrorStack> {
8584
unsafe {
86-
cvt(ffi::ENGINE_remove(self.as_ptr()))?;
85+
return cvt(ffi::ENGINE_remove(self.as_ptr()));
8786
}
88-
Ok(())
8987
}
9088

9189
/// Returns an engine with the passed in `id`.
@@ -102,11 +100,10 @@ impl Engine {
102100
/// Remove all references to the passed in engine.
103101
#[corresponds(ENGINE_finish)]
104102
#[inline]
105-
pub fn finish(&mut self) -> Result<(), ErrorStack> {
103+
pub fn finish(&mut self) -> Result<i32, ErrorStack> {
106104
unsafe {
107-
cvt(ffi::ENGINE_finish(self.as_ptr()))?;
105+
return cvt(ffi::ENGINE_finish(self.as_ptr()));
108106
}
109-
Ok(())
110107
}
111108

112109
/// Loads the builtin engines.
@@ -181,82 +178,83 @@ impl Engine {
181178
/// Sets the default RSA engine.
182179
#[corresponds(ENGINE_set_default_RSA)]
183180
#[inline]
184-
pub fn set_default_rsa(&mut self) -> Result<(), ErrorStack> {
181+
pub fn set_default_rsa(&mut self) -> Result<i32, ErrorStack> {
185182
unsafe {
186-
cvt(ffi::ENGINE_set_default_RSA(self.as_ptr()))?;
183+
let result = cvt(ffi::ENGINE_set_default_RSA(self.as_ptr()))?;
184+
Ok(result)
187185
}
188-
Ok(())
189186
}
190187

191188
/// Sets the default DSA engine.
192189
#[corresponds(ENGINE_set_default_DSA)]
193190
#[inline]
194-
pub fn set_default_dsa(&mut self) -> Result<(), ErrorStack> {
191+
pub fn set_default_dsa(&mut self) -> Result<i32, ErrorStack> {
195192
unsafe {
196-
cvt(ffi::ENGINE_set_default_DSA(self.as_ptr()))?;
193+
return cvt(ffi::ENGINE_set_default_DSA(self.as_ptr()));
197194
}
198-
Ok(())
199195
}
200196

201197
/// Sets the default DH engine.
202198
#[corresponds(ENGINE_set_default_DH)]
203199
#[inline]
204-
pub fn set_default_dh(&mut self) -> Result<(), ErrorStack> {
200+
pub fn set_default_dh(&mut self) -> Result<i32, ErrorStack> {
205201
unsafe {
206-
cvt(ffi::ENGINE_set_default_DH(self.as_ptr()))?;
202+
return cvt(ffi::ENGINE_set_default_DH(self.as_ptr()));
207203
}
208-
Ok(())
209204
}
210205

211206
/// Sets the default RAND engine.
212207
#[corresponds(ENGINE_set_default_RAND)]
213208
#[inline]
214-
pub fn set_default_rand(&mut self) -> Result<(), ErrorStack> {
209+
pub fn set_default_rand(&mut self) -> Result<i32, ErrorStack> {
215210
unsafe {
216-
cvt(ffi::ENGINE_set_default_RAND(self.as_ptr()))?;
211+
return cvt(ffi::ENGINE_set_default_RAND(self.as_ptr()));
217212
}
218-
Ok(())
219213
}
220214

221215
/// Sets the default ciphers engine.
222216
#[corresponds(ENGINE_set_default_ciphers)]
223217
#[inline]
224-
pub fn set_default_ciphers(&mut self) -> Result<(), ErrorStack> {
218+
pub fn set_default_ciphers(&mut self) -> Result<i32, ErrorStack> {
225219
unsafe {
226-
cvt(ffi::ENGINE_set_default_ciphers(self.as_ptr()))?;
220+
return cvt(ffi::ENGINE_set_default_ciphers(self.as_ptr()));
227221
}
228-
Ok(())
229222
}
230223

231224
/// Sets the default digests engine.
232225
#[corresponds(ENGINE_set_default_digests)]
233226
#[inline]
234-
pub fn set_default_digests(&mut self) -> Result<(), ErrorStack> {
227+
pub fn set_default_digests(&mut self) -> Result<i32, ErrorStack> {
235228
unsafe {
236-
cvt(ffi::ENGINE_set_default_digests(self.as_ptr()))?;
229+
return cvt(ffi::ENGINE_set_default_digests(self.as_ptr()));
237230
}
238-
Ok(())
239231
}
240232

241233
/// Sets the default string for the engine.
242234
#[corresponds(ENGINE_set_default_string)]
243235
#[inline]
244-
pub fn set_default_string(&mut self, list: &str) -> Result<(), ErrorStack> {
236+
pub fn set_default_string(&mut self, list: &str) -> Result<i32, ErrorStack> {
245237
let list = CString::new(list).unwrap();
246238
unsafe {
247-
cvt(ffi::ENGINE_set_default_string(self.as_ptr(), list.as_ptr()))?;
239+
return cvt(ffi::ENGINE_set_default_string(self.as_ptr(), list.as_ptr()));
240+
}
241+
}
242+
/// Sets the default engine.
243+
#[corresponds(ENGINE_init)]
244+
#[inline]
245+
pub fn init(&mut self) -> Result<i32, ErrorStack> {
246+
unsafe {
247+
return cvt(ffi::ENGINE_init(self.as_ptr()));
248248
}
249-
Ok(())
250249
}
251250

252251
/// Sets the default engine.
253252
#[corresponds(ENGINE_set_default)]
254253
#[inline]
255-
pub fn set_default(&mut self, flags: u32) -> Result<(), ErrorStack> {
254+
pub fn set_default(&mut self, flags: u32) -> Result<i32, ErrorStack> {
256255
unsafe {
257-
cvt(ffi::ENGINE_set_default(self.as_ptr(), flags))?;
256+
return cvt(ffi::ENGINE_set_default(self.as_ptr(), flags));
258257
}
259-
Ok(())
260258
}
261259

262260
/// Returns the (global?) engine table flags.
@@ -280,11 +278,10 @@ impl Engine {
280278
/// Registers the input engine as the RSA engine.
281279
#[corresponds(ENGINE_register_RSA)]
282280
#[inline]
283-
pub fn register_rsa(&mut self) -> Result<(), ErrorStack> {
281+
pub fn register_rsa(&mut self) -> Result<i32, ErrorStack> {
284282
unsafe {
285-
cvt(ffi::ENGINE_register_RSA(self.as_ptr()))?;
283+
return cvt(ffi::ENGINE_register_RSA(self.as_ptr()));
286284
}
287-
Ok(())
288285
}
289286

290287
/// Unregisters the input engine as the RSA engine.
@@ -308,11 +305,10 @@ impl Engine {
308305
/// Registers the input engine as the DSA engine.
309306
#[corresponds(ENGINE_register_DSA)]
310307
#[inline]
311-
pub fn register_dsa(&mut self) -> Result<(), ErrorStack> {
308+
pub fn register_dsa(&mut self) -> Result<i32, ErrorStack> {
312309
unsafe {
313-
cvt(ffi::ENGINE_register_DSA(self.as_ptr()))?;
310+
return cvt(ffi::ENGINE_register_DSA(self.as_ptr()));
314311
}
315-
Ok(())
316312
}
317313

318314
/// Unregisters the input engine as the DSA engine.
@@ -336,11 +332,10 @@ impl Engine {
336332
/// Registers the input engine as the DH engine.
337333
#[corresponds(ENGINE_register_DH)]
338334
#[inline]
339-
pub fn register_dh(&mut self) -> Result<(), ErrorStack> {
335+
pub fn register_dh(&mut self) -> Result<i32, ErrorStack> {
340336
unsafe {
341-
cvt(ffi::ENGINE_register_DH(self.as_ptr()))?;
337+
return cvt(ffi::ENGINE_register_DH(self.as_ptr()));
342338
}
343-
Ok(())
344339
}
345340

346341
/// Unregisters the input engine as the DH engine.
@@ -364,11 +359,10 @@ impl Engine {
364359
/// Registers the input engine as the RAND engine.
365360
#[corresponds(ENGINE_register_RAND)]
366361
#[inline]
367-
pub fn register_rand(&mut self) -> Result<(), ErrorStack> {
362+
pub fn register_rand(&mut self) -> Result<i32, ErrorStack> {
368363
unsafe {
369-
cvt(ffi::ENGINE_register_RAND(self.as_ptr()))?;
364+
return cvt(ffi::ENGINE_register_RAND(self.as_ptr()));
370365
}
371-
Ok(())
372366
}
373367

374368
/// Unregisters the input engine as the RAND engine.
@@ -392,11 +386,10 @@ impl Engine {
392386
/// Registers ciphers from the input engine.
393387
#[corresponds(ENGINE_register_ciphers)]
394388
#[inline]
395-
pub fn register_ciphers(&mut self) -> Result<(), ErrorStack> {
389+
pub fn register_ciphers(&mut self) -> Result<i32, ErrorStack> {
396390
unsafe {
397-
cvt(ffi::ENGINE_register_ciphers(self.as_ptr()))?;
391+
return cvt(ffi::ENGINE_register_ciphers(self.as_ptr()));
398392
}
399-
Ok(())
400393
}
401394

402395
/// Unregisters the ciphers from the input engine.
@@ -420,11 +413,10 @@ impl Engine {
420413
/// Registers digests from the input engine.
421414
#[corresponds(ENGINE_register_digests)]
422415
#[inline]
423-
pub fn register_digests(&mut self) -> Result<(), ErrorStack> {
416+
pub fn register_digests(&mut self) -> Result<i32, ErrorStack> {
424417
unsafe {
425-
cvt(ffi::ENGINE_register_digests(self.as_ptr()))?;
418+
return cvt(ffi::ENGINE_register_digests(self.as_ptr()));
426419
}
427-
Ok(())
428420
}
429421

430422
/// Unregisters the digests from the input engine.
@@ -447,20 +439,18 @@ impl Engine {
447439

448440
#[corresponds(ENGINE_register_complete)]
449441
#[inline]
450-
pub fn register_complete(&mut self) -> Result<(), ErrorStack> {
442+
pub fn register_complete(&mut self) -> Result<i32, ErrorStack> {
451443
unsafe {
452-
cvt(ffi::ENGINE_register_complete(self.as_ptr()))?;
444+
return cvt(ffi::ENGINE_register_complete(self.as_ptr()));
453445
}
454-
Ok(())
455446
}
456447

457448
#[corresponds(ENGINE_register_all_complete)]
458449
#[inline]
459-
pub fn register_all_complete() -> Result<(), ErrorStack> {
450+
pub fn register_all_complete() -> Result<i32, ErrorStack> {
460451
unsafe {
461-
cvt(ffi::ENGINE_register_all_complete())?;
452+
return cvt(ffi::ENGINE_register_all_complete());
462453
}
463-
Ok(())
464454
}
465455

466456
#[corresponds(ENGINE_ctrl)]
@@ -477,11 +467,10 @@ impl Engine {
477467

478468
#[corresponds(ENGINE_cmd_is_executable)]
479469
#[inline]
480-
pub fn cmd_is_executable(&mut self, cmd: i32) -> Result<(), ErrorStack> {
470+
pub fn cmd_is_executable(&mut self, cmd: i32) -> Result<i32, ErrorStack> {
481471
unsafe {
482-
cvt(ffi::ENGINE_cmd_is_executable(self.as_ptr(), cmd))?;
472+
return cvt(ffi::ENGINE_cmd_is_executable(self.as_ptr(), cmd));
483473
}
484-
Ok(())
485474
}
486475

487476
#[corresponds(ENGINE_ctrl_cmd)]
@@ -497,39 +486,49 @@ impl Engine {
497486
_cmd: &str,
498487
_arg: &str,
499488
_optional: i32,
500-
) -> Result<(), ErrorStack> {
501-
todo!();
489+
) -> Result<i32, ErrorStack> {
490+
let cmd = CString::new(_cmd).unwrap();
491+
let arg = CString::new(_arg).unwrap();
492+
unsafe {
493+
return cvt(ffi::ENGINE_ctrl_cmd_string(self.as_ptr(), cmd.as_ptr(), arg.as_ptr(), 0));
494+
}
495+
}
496+
#[corresponds(ENGINE_ctrl_cmd_string)]
497+
#[inline]
498+
pub fn load(
499+
&mut self
500+
) -> Result<i32, ErrorStack> {
501+
let cmd = CString::new("LOAD").unwrap();
502+
unsafe {
503+
return cvt(ffi::ENGINE_ctrl_cmd_string(self.as_ptr(), cmd.as_ptr(), std::ptr::null(), 0));
504+
}
502505
}
503-
504506
#[corresponds(ENGINE_up_ref)]
505507
#[inline]
506-
pub fn up_ref(&mut self) -> Result<(), ErrorStack> {
508+
pub fn up_ref(&mut self) -> Result<i32, ErrorStack> {
507509
unsafe {
508-
cvt(ffi::ENGINE_up_ref(self.as_ptr()))?;
510+
return cvt(ffi::ENGINE_up_ref(self.as_ptr()));
509511
}
510-
Ok(())
511512
}
512513

513514
/// Sets the ID on the engine.
514515
#[corresponds(ENGINE_set_id)]
515516
#[inline]
516-
pub fn set_id(&mut self, id: &str) -> Result<(), ErrorStack> {
517+
pub fn set_id(&mut self, id: &str) -> Result<i32, ErrorStack> {
517518
let id = CString::new(id).unwrap();
518519
unsafe {
519-
cvt(ffi::ENGINE_set_id(self.as_ptr(), id.as_ptr()))?;
520+
return cvt(ffi::ENGINE_set_id(self.as_ptr(), id.as_ptr()));
520521
}
521-
Ok(())
522522
}
523523

524524
/// Sets the name on the engine.
525525
#[corresponds(ENGINE_set_name)]
526526
#[inline]
527-
pub fn set_name(&mut self, name: &str) -> Result<(), ErrorStack> {
527+
pub fn set_name(&mut self, name: &str) -> Result<i32, ErrorStack> {
528528
let name = CString::new(name).unwrap();
529529
unsafe {
530-
cvt(ffi::ENGINE_set_name(self.as_ptr(), name.as_ptr()))?;
530+
return cvt(ffi::ENGINE_set_name(self.as_ptr(), name.as_ptr()));
531531
}
532-
Ok(())
533532
}
534533

535534
/// Sets the RSA method on the engine.

0 commit comments

Comments
 (0)