aboutsummaryrefslogtreecommitdiff
path: root/openssl/src
diff options
context:
space:
mode:
authorSteven Fackler <[email protected]>2015-02-16 22:21:13 -0800
committerSteven Fackler <[email protected]>2015-02-16 22:21:13 -0800
commitf0eb8e39e3af70c7e0322f0d698f6714ad723c62 (patch)
tree28b265bf1ea4cda743d389302a72399950ffb5a9 /openssl/src
parentRelease v0.4.0 (diff)
downloadrust-openssl-f0eb8e39e3af70c7e0322f0d698f6714ad723c62.tar.xz
rust-openssl-f0eb8e39e3af70c7e0322f0d698f6714ad723c62.zip
Deal with openssl errors in read
I'm not sure of a great way to generate this case in a test, unfortunately. Closes #157
Diffstat (limited to 'openssl/src')
-rw-r--r--openssl/src/ssl/error.rs18
-rw-r--r--openssl/src/ssl/mod.rs12
2 files changed, 26 insertions, 4 deletions
diff --git a/openssl/src/ssl/error.rs b/openssl/src/ssl/error.rs
index 027554c5..a80c244e 100644
--- a/openssl/src/ssl/error.rs
+++ b/openssl/src/ssl/error.rs
@@ -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(())
}
}
diff --git a/openssl/src/ssl/mod.rs b/openssl/src/ssl/mod.rs
index c9d46ffc..0c698f54 100644
--- a/openssl/src/ssl/mod.rs
+++ b/openssl/src/ssl/mod.rs
@@ -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)),
+ })
+ }
}
}
}