Deal with openssl errors in read
I'm not sure of a great way to generate this case in a test, unfortunately. Closes #157
This commit is contained in:
parent
4350298a52
commit
f0eb8e39e3
|
|
@ -22,7 +22,23 @@ pub enum SslError {
|
|||
|
||||
impl fmt::Display for SslError {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
fmt.write_str(error::Error::description(self))
|
||||
try!(fmt.write_str(error::Error::description(self)));
|
||||
if let OpenSslErrors(ref errs) = *self {
|
||||
let mut first = true;
|
||||
for err in errs {
|
||||
if first {
|
||||
try!(fmt.write_str(": "));
|
||||
first = false;
|
||||
} else {
|
||||
try!(fmt.write_str(", "));
|
||||
}
|
||||
match *err {
|
||||
UnknownError { ref reason, .. } => try!(fmt.write_str(reason)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use libc::{c_int, c_void, c_long};
|
||||
use std::ffi::{CString, c_str_to_bytes};
|
||||
use std::old_io::{IoResult, IoError, EndOfFile, Stream, Reader, Writer};
|
||||
use std::old_io::{IoResult, IoError, EndOfFile, OtherIoError, Stream, Reader, Writer};
|
||||
use std::mem;
|
||||
use std::fmt;
|
||||
use std::num::FromPrimitive;
|
||||
|
|
@ -9,7 +9,7 @@ use std::sync::{Once, ONCE_INIT, Arc};
|
|||
|
||||
use bio::{MemBio};
|
||||
use ffi;
|
||||
use ssl::error::{SslError, SslSessionClosed, StreamError};
|
||||
use ssl::error::{SslError, SslSessionClosed, StreamError, OpenSslErrors};
|
||||
use x509::{X509StoreContext, X509FileType, X509};
|
||||
|
||||
pub mod error;
|
||||
|
|
@ -559,7 +559,13 @@ impl<S: Stream> Reader for SslStream<S> {
|
|||
detail: None
|
||||
}),
|
||||
Err(StreamError(e)) => Err(e),
|
||||
_ => unreachable!()
|
||||
Err(e @ OpenSslErrors(_)) => {
|
||||
Err(IoError {
|
||||
kind: OtherIoError,
|
||||
desc: "SSL error",
|
||||
detail: Some(format!("{}", e)),
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue