Loading error.rs +17 −8 Original line number Diff line number Diff line Loading @@ -6,6 +6,11 @@ use super::ffi; pub enum SslError { StreamEof, SslSessionClosed, OpenSslErrors(~[OpensslError]) } #[deriving(ToStr)] pub enum OpensslError { UnknownError { library: u8, function: u16, Loading @@ -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) } } lib.rs +6 −6 Original line number Diff line number Diff line Loading @@ -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 }) Loading Loading @@ -130,7 +130,7 @@ impl SslContext { }; if ret == 0 { Some(SslError::get().unwrap()) Some(SslError::get()) } else { None } Loading @@ -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) } Loading Loading @@ -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!() } } Loading Loading
error.rs +17 −8 Original line number Diff line number Diff line Loading @@ -6,6 +6,11 @@ use super::ffi; pub enum SslError { StreamEof, SslSessionClosed, OpenSslErrors(~[OpensslError]) } #[deriving(ToStr)] pub enum OpensslError { UnknownError { library: u8, function: u16, Loading @@ -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) } }
lib.rs +6 −6 Original line number Diff line number Diff line Loading @@ -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 }) Loading Loading @@ -130,7 +130,7 @@ impl SslContext { }; if ret == 0 { Some(SslError::get().unwrap()) Some(SslError::get()) } else { None } Loading @@ -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) } Loading Loading @@ -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!() } } Loading