diff options
author | Steven Fackler <sfackler@gmail.com> | 2014-08-03 19:16:09 -0700 |
---|---|---|
committer | Steven Fackler <sfackler@gmail.com> | 2014-08-03 19:16:09 -0700 |
commit | 203bdd076ec744a1794a7b151efb6b9247d43455 (patch) | |
tree | 8b4e69b8bdfd834648b73243519f4eeca301bb90 /src/ssl/error.rs | |
parent | 497734d3e80174e327c0254cf5fa00ab362f9051 (diff) | |
download | rust-openssl-203bdd076ec744a1794a7b151efb6b9247d43455.zip |
Shift directory structure
Diffstat (limited to 'src/ssl/error.rs')
-rw-r--r-- | src/ssl/error.rs | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/src/ssl/error.rs b/src/ssl/error.rs new file mode 100644 index 00000000..dd387e2f --- /dev/null +++ b/src/ssl/error.rs @@ -0,0 +1,60 @@ +use libc::c_ulong; +use std::io::IoError; + +use ssl::ffi; + +/// An SSL error +#[deriving(Show)] +pub enum SslError { + /// The underlying stream has reported an error + StreamError(IoError), + /// The SSL session has been closed by the other end + SslSessionClosed, + /// An error in the OpenSSL library + OpenSslErrors(Vec<OpensslError>) +} + +/// An error from the OpenSSL library +#[deriving(Show)] +pub enum OpensslError { + /// An unknown error + UnknownError { + /// The library reporting the error + library: u8, + /// The function reporting the error + function: u16, + /// The reason for the error + reason: u16 + } +} + +fn get_lib(err: c_ulong) -> u8 { + ((err >> 24) & 0xff) as u8 +} + +fn get_func(err: c_ulong) -> u16 { + ((err >> 12) & 0xfff) as u16 +} + +fn get_reason(err: c_ulong) -> u16 { + (err & 0xfff) as u16 +} + +impl SslError { + /// Creates a new `OpenSslErrors` with the current contents of the error + /// stack. + pub fn get() -> SslError { + let mut errs = vec!(); + 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) + }) + } + } + OpenSslErrors(errs) + } +} |