Commit 7ea442be authored by Steven Fackler's avatar Steven Fackler
Browse files

Ssl errors may return a stack

parent eea07ef1
Loading
Loading
Loading
Loading
+17 −8
Original line number Diff line number Diff line
@@ -6,6 +6,11 @@ use super::ffi;
pub enum SslError {
    StreamEof,
    SslSessionClosed,
    OpenSslErrors(~[OpensslError])
}

#[deriving(ToStr)]
pub enum OpensslError {
    UnknownError {
        library: u8,
        function: u16,
@@ -26,14 +31,18 @@ fn get_reason(err: c_ulong) -> u16 {
}

impl SslError {
    pub fn get() -> Option<SslError> {
    pub fn get() -> SslError {
        let mut errs = ~[];
        loop {
            match unsafe { ffi::ERR_get_error() } {
            0 => None,
            err => Some(UnknownError {
                0 => break,
                err => errs.push(UnknownError {
                    library: get_lib(err),
                    function: get_func(err),
                    reason: get_reason(err)
                })
            }
        }
        OpenSslErrors(errs)
    }
}
+6 −6
Original line number Diff line number Diff line
@@ -98,7 +98,7 @@ impl SslContext {

        let ctx = unsafe { ffi::SSL_CTX_new(method.to_raw()) };
        if ctx == ptr::null() {
            return Err(SslError::get().unwrap());
            return Err(SslError::get());
        }

        Ok(SslContext { ctx: ctx })
@@ -130,7 +130,7 @@ impl SslContext {
        };

        if ret == 0 {
            Some(SslError::get().unwrap())
            Some(SslError::get())
        } else {
            None
        }
@@ -151,19 +151,19 @@ impl Ssl {
    fn try_new(ctx: &SslContext) -> Result<Ssl, SslError> {
        let ssl = unsafe { ffi::SSL_new(ctx.ctx) };
        if ssl == ptr::null() {
            return Err(SslError::get().unwrap());
            return Err(SslError::get());
        }
        let ssl = Ssl { ssl: ssl };

        let rbio = unsafe { ffi::BIO_new(ffi::BIO_s_mem()) };
        if rbio == ptr::null() {
            return Err(SslError::get().unwrap());
            return Err(SslError::get());
        }

        let wbio = unsafe { ffi::BIO_new(ffi::BIO_s_mem()) };
        if wbio == ptr::null() {
            unsafe { ffi::BIO_free_all(rbio) }
            return Err(SslError::get().unwrap());
            return Err(SslError::get());
        }

        unsafe { ffi::SSL_set_bio(ssl.ssl, rbio, wbio) }
@@ -307,7 +307,7 @@ impl<S: Stream> SslStream<S> {
                }
                ErrorWantWrite => self.flush(),
                ErrorZeroReturn => return Err(SslSessionClosed),
                ErrorSsl => return Err(SslError::get().unwrap()),
                ErrorSsl => return Err(SslError::get()),
                _ => unreachable!()
            }
        }