aboutsummaryrefslogtreecommitdiff
path: root/openssl/src/util.rs
diff options
context:
space:
mode:
authorSteven Fackler <[email protected]>2016-11-13 15:02:38 +0000
committerSteven Fackler <[email protected]>2016-11-13 15:02:38 +0000
commit08e0c4ca9061c3dc0c951db0c08909689b04a310 (patch)
tree117d95bb3cc28cf88cdedb97c985bbe9db436415 /openssl/src/util.rs
parentNo need to use a raw string anymore (diff)
downloadrust-openssl-08e0c4ca9061c3dc0c951db0c08909689b04a310.tar.xz
rust-openssl-08e0c4ca9061c3dc0c951db0c08909689b04a310.zip
Some serialization support for EcKey
Diffstat (limited to 'openssl/src/util.rs')
-rw-r--r--openssl/src/util.rs31
1 files changed, 26 insertions, 5 deletions
diff --git a/openssl/src/util.rs b/openssl/src/util.rs
index 302bd316..dea94668 100644
--- a/openssl/src/util.rs
+++ b/openssl/src/util.rs
@@ -33,10 +33,7 @@ impl<F> Drop for CallbackState<F> {
}
}
-/// Password callback function, passed to private key loading functions.
-///
-/// `cb_state` is expected to be a pointer to a `CallbackState`.
-pub unsafe extern "C" fn invoke_passwd_cb<F>(buf: *mut c_char,
+pub unsafe extern fn invoke_passwd_cb_old<F>(buf: *mut c_char,
size: c_int,
_rwflag: c_int,
cb_state: *mut c_void)
@@ -46,9 +43,33 @@ pub unsafe extern "C" fn invoke_passwd_cb<F>(buf: *mut c_char,
let callback = &mut *(cb_state as *mut CallbackState<F>);
let result = panic::catch_unwind(AssertUnwindSafe(|| {
- // build a `i8` slice to pass to the user callback
let pass_slice = slice::from_raw_parts_mut(buf, size as usize);
+ callback.cb.take().unwrap()(pass_slice)
+ }));
+ match result {
+ Ok(len) => len as c_int,
+ Err(err) => {
+ callback.panic = Some(err);
+ 0
+ }
+ }
+}
+
+/// Password callback function, passed to private key loading functions.
+///
+/// `cb_state` is expected to be a pointer to a `CallbackState`.
+pub unsafe extern fn invoke_passwd_cb<F>(buf: *mut c_char,
+ size: c_int,
+ _rwflag: c_int,
+ cb_state: *mut c_void)
+ -> c_int
+ where F: FnOnce(&mut [u8]) -> usize
+{
+ let callback = &mut *(cb_state as *mut CallbackState<F>);
+
+ let result = panic::catch_unwind(AssertUnwindSafe(|| {
+ let pass_slice = slice::from_raw_parts_mut(buf as *mut u8, size as usize);
callback.cb.take().unwrap()(pass_slice)
}));