aboutsummaryrefslogtreecommitdiff
path: root/src/ssl/error.rs
diff options
context:
space:
mode:
authorSteven Fackler <[email protected]>2014-10-05 16:40:01 -0400
committerSteven Fackler <[email protected]>2014-10-05 16:40:01 -0400
commitd136a6bb572e1fdee114ad246c17e9e169d08935 (patch)
treecc33db889fdbfd7724130c176b549d4320c64db2 /src/ssl/error.rs
parentClean up warnings (diff)
parentLoad crypto error strings (diff)
downloadrust-openssl-d136a6bb572e1fdee114ad246c17e9e169d08935.tar.xz
rust-openssl-d136a6bb572e1fdee114ad246c17e9e169d08935.zip
Merge pull request #59 from jroesch/better-errors
Make errors human readable
Diffstat (limited to 'src/ssl/error.rs')
-rw-r--r--src/ssl/error.rs31
1 files changed, 22 insertions, 9 deletions
diff --git a/src/ssl/error.rs b/src/ssl/error.rs
index 452f8aad..0c1af90a 100644
--- a/src/ssl/error.rs
+++ b/src/ssl/error.rs
@@ -1,5 +1,6 @@
use libc::c_ulong;
use std::io::IoError;
+use std::c_str::CString;
use ffi;
@@ -20,24 +21,36 @@ pub enum OpensslError {
/// An unknown error
UnknownError {
/// The library reporting the error
- library: u8,
+ library: String,
/// The function reporting the error
- function: u16,
+ function: String,
/// The reason for the error
- reason: u16
+ reason: String
}
}
-fn get_lib(err: c_ulong) -> u8 {
- ((err >> 24) & 0xff) as u8
+fn get_lib(err: c_ulong) -> String {
+ unsafe { CString::new(ffi::ERR_lib_error_string(err), false) }.to_string()
}
-fn get_func(err: c_ulong) -> u16 {
- ((err >> 12) & 0xfff) as u16
+fn get_func(err: c_ulong) -> String {
+ unsafe { CString::new(ffi::ERR_func_error_string(err), false).to_string() }
}
-fn get_reason(err: c_ulong) -> u16 {
- (err & 0xfff) as u16
+fn get_reason(err: c_ulong) -> String {
+ unsafe { CString::new(ffi::ERR_reason_error_string(err), false).to_string() }
+}
+
+#[test]
+fn test_uknown_error_should_have_correct_messages() {
+ let err = 336032784;
+ let library = get_lib(err);
+ let function = get_func(err);
+ let reason = get_reason(err);
+
+ assert_eq!(library.as_slice(),"SSL routines");
+ assert_eq!(function.as_slice(), "SSL23_GET_SERVER_HELLO");
+ assert_eq!(reason.as_slice(), "sslv3 alert handshake failure");
}
impl SslError {