aboutsummaryrefslogtreecommitdiff
path: root/src/ssl/lib.rs
diff options
context:
space:
mode:
authorSteven Fackler <[email protected]>2013-10-13 21:56:57 -0700
committerSteven Fackler <[email protected]>2013-10-13 21:56:57 -0700
commit0fac64705eb7cbd1a314d7e9fb7301dfda19b760 (patch)
treeebe813bc3c2f21dfd029d0a620dcea09917a344a /src/ssl/lib.rs
parentStart of cert verification (diff)
downloadrust-openssl-0fac64705eb7cbd1a314d7e9fb7301dfda19b760.tar.xz
rust-openssl-0fac64705eb7cbd1a314d7e9fb7301dfda19b760.zip
Clean up SslError conversion
Diffstat (limited to 'src/ssl/lib.rs')
-rw-r--r--src/ssl/lib.rs37
1 files changed, 15 insertions, 22 deletions
diff --git a/src/ssl/lib.rs b/src/ssl/lib.rs
index faf9e651..50565602 100644
--- a/src/ssl/lib.rs
+++ b/src/ssl/lib.rs
@@ -70,17 +70,17 @@ pub enum SslVerifyMode {
SslVerifyPeer = ffi::SSL_VERIFY_PEER
}
-#[deriving(Eq, TotalEq, ToStr)]
+#[deriving(Eq, FromPrimitive)]
enum SslError {
- ErrorNone,
- ErrorSsl,
- ErrorWantRead,
- ErrorWantWrite,
- ErrorWantX509Lookup,
- ErrorSyscall,
- ErrorZeroReturn,
- ErrorWantConnect,
- ErrorWantAccept,
+ ErrorNone = ffi::SSL_ERROR_NONE,
+ ErrorSsl = ffi::SSL_ERROR_SSL,
+ ErrorWantRead = ffi::SSL_ERROR_WANT_READ,
+ ErrorWantWrite = ffi::SSL_ERROR_WANT_WRITE,
+ ErrorWantX509Lookup = ffi::SSL_ERROR_WANT_X509_LOOKUP,
+ ErrorSyscall = ffi::SSL_ERROR_SYSCALL,
+ ErrorZeroReturn = ffi::SSL_ERROR_ZERO_RETURN,
+ ErrorWantConnect = ffi::SSL_ERROR_WANT_CONNECT,
+ ErrorWantAccept = ffi::SSL_ERROR_WANT_ACCEPT,
}
struct Ssl {
@@ -114,17 +114,10 @@ impl Ssl {
}
fn get_error(&self, ret: int) -> SslError {
- match unsafe { ffi::SSL_get_error(self.ssl, ret as c_int) } {
- ffi::SSL_ERROR_NONE => ErrorNone,
- ffi::SSL_ERROR_SSL => ErrorSsl,
- ffi::SSL_ERROR_WANT_READ => ErrorWantRead,
- ffi::SSL_ERROR_WANT_WRITE => ErrorWantWrite,
- ffi::SSL_ERROR_WANT_X509_LOOKUP => ErrorWantX509Lookup,
- ffi::SSL_ERROR_SYSCALL => ErrorSyscall,
- ffi::SSL_ERROR_ZERO_RETURN => ErrorZeroReturn,
- ffi::SSL_ERROR_WANT_CONNECT => ErrorWantConnect,
- ffi::SSL_ERROR_WANT_ACCEPT => ErrorWantAccept,
- err => fail2!("Unknown error {}", err)
+ let err = unsafe { ffi::SSL_get_error(self.ssl, ret as c_int) };
+ match FromPrimitive::from_int(err as int) {
+ Some(err) => err,
+ None => fail2!("Unknown error {}", err)
}
}
@@ -294,7 +287,7 @@ impl<S: Stream> Writer for SslStream<S> {
match ret {
Ok(_) => (),
- Err(err) => fail2!("Write error: {}", err.to_str())
+ Err(err) => fail2!("Write error: {:?}", err)
}
self.write_through();