diff options
| author | Jared Roesch <[email protected]> | 2014-10-11 01:50:34 -0700 |
|---|---|---|
| committer | Jared Roesch <[email protected]> | 2014-10-11 01:57:33 -0700 |
| commit | 5f017cd549b4c76849bfd5c33e6f6962acd89535 (patch) | |
| tree | 4ea8770a90ca801e48e65032f756dccef069b5c5 /src/ssl/error.rs | |
| parent | Merge pull request #62 from vhbit/feature-matrix (diff) | |
| download | rust-openssl-5f017cd549b4c76849bfd5c33e6f6962acd89535.tar.xz rust-openssl-5f017cd549b4c76849bfd5c33e6f6962acd89535.zip | |
Refactor init and error handling code
Move common ffi initialization code to 'ffi::init()' and the initialization of error handling to a
a shared location.
Diffstat (limited to 'src/ssl/error.rs')
| -rw-r--r-- | src/ssl/error.rs | 47 |
1 files changed, 29 insertions, 18 deletions
diff --git a/src/ssl/error.rs b/src/ssl/error.rs index 56105253..5af6c866 100644 --- a/src/ssl/error.rs +++ b/src/ssl/error.rs @@ -41,19 +41,6 @@ fn get_reason(err: c_ulong) -> String { unsafe { CString::new(ffi::ERR_reason_error_string(err), false).to_string() } } -#[test] -#[ignore] // FIXME #65 -fn test_uknown_error_should_have_correct_messages() { - let err = 336032784; - let library = get_lib(err); - let function = get_func(err); - let reason = get_reason(err); - - assert_eq!(library.as_slice(),"SSL routines"); - assert_eq!(function.as_slice(), "SSL23_GET_SERVER_HELLO"); - assert_eq!(reason.as_slice(), "sslv3 alert handshake failure"); -} - impl SslError { /// Creates a new `OpenSslErrors` with the current contents of the error /// stack. @@ -62,13 +49,37 @@ impl SslError { loop { match unsafe { ffi::ERR_get_error() } { 0 => break, - err => errs.push(UnknownError { - library: get_lib(err), - function: get_func(err), - reason: get_reason(err) - }) + err => errs.push(SslError::from_error_code(err)) } } OpenSslErrors(errs) } + + /// Creates an `SslError` from the raw numeric error code. + pub fn from_error(err: c_ulong) -> SslError { + OpenSslErrors(vec![SslError::from_error_code(err)]) + } + + fn from_error_code(err: c_ulong) -> OpensslError { + ffi::init(); + UnknownError { + library: get_lib(err), + function: get_func(err), + reason: get_reason(err) + } + } +} + +#[test] +fn test_uknown_error_should_have_correct_messages() { + let errs = match SslError::from_error(336032784) { + OpenSslErrors(errs) => errs, + _ => fail!("This should always be an `OpenSslErrors` variant.") + }; + + let UnknownError { ref library, ref function, ref reason } = errs[0]; + + assert_eq!(library.as_slice(),"SSL routines"); + assert_eq!(function.as_slice(), "SSL23_GET_SERVER_HELLO"); + assert_eq!(reason.as_slice(), "sslv3 alert handshake failure"); } |