Merge pull request #59 from jroesch/better-errors
Make errors human readable
This commit is contained in:
commit
d136a6bb57
|
|
@ -272,6 +272,12 @@ extern "C" {
|
||||||
|
|
||||||
pub fn ERR_get_error() -> c_ulong;
|
pub fn ERR_get_error() -> c_ulong;
|
||||||
|
|
||||||
|
pub fn ERR_lib_error_string(err: c_ulong) -> *const c_char;
|
||||||
|
pub fn ERR_func_error_string(err: c_ulong) -> *const c_char;
|
||||||
|
pub fn ERR_reason_error_string(err: c_ulong) -> *const c_char;
|
||||||
|
|
||||||
|
pub fn ERR_load_crypto_strings();
|
||||||
|
|
||||||
pub fn EVP_md5() -> *const EVP_MD;
|
pub fn EVP_md5() -> *const EVP_MD;
|
||||||
pub fn EVP_ripemd160() -> *const EVP_MD;
|
pub fn EVP_ripemd160() -> *const EVP_MD;
|
||||||
pub fn EVP_sha1() -> *const EVP_MD;
|
pub fn EVP_sha1() -> *const EVP_MD;
|
||||||
|
|
@ -345,6 +351,8 @@ extern "C" {
|
||||||
|
|
||||||
pub fn SSL_library_init() -> c_int;
|
pub fn SSL_library_init() -> c_int;
|
||||||
|
|
||||||
|
pub fn SSL_load_error_strings();
|
||||||
|
|
||||||
#[cfg(feature = "sslv2")]
|
#[cfg(feature = "sslv2")]
|
||||||
pub fn SSLv2_method() -> *const SSL_METHOD;
|
pub fn SSLv2_method() -> *const SSL_METHOD;
|
||||||
pub fn SSLv3_method() -> *const SSL_METHOD;
|
pub fn SSLv3_method() -> *const SSL_METHOD;
|
||||||
|
|
@ -421,4 +429,3 @@ extern "C" {
|
||||||
pub fn i2d_RSAPrivateKey(k: *mut RSA, buf: *const *mut u8) -> c_int;
|
pub fn i2d_RSAPrivateKey(k: *mut RSA, buf: *const *mut u8) -> c_int;
|
||||||
pub fn d2i_RSAPrivateKey(k: *const *mut RSA, buf: *const *const u8, len: c_uint) -> *mut RSA;
|
pub fn d2i_RSAPrivateKey(k: *const *mut RSA, buf: *const *const u8, len: c_uint) -> *mut RSA;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
use libc::c_ulong;
|
use libc::c_ulong;
|
||||||
use std::io::IoError;
|
use std::io::IoError;
|
||||||
|
use std::c_str::CString;
|
||||||
|
|
||||||
use ffi;
|
use ffi;
|
||||||
|
|
||||||
|
|
@ -20,24 +21,36 @@ pub enum OpensslError {
|
||||||
/// An unknown error
|
/// An unknown error
|
||||||
UnknownError {
|
UnknownError {
|
||||||
/// The library reporting the error
|
/// The library reporting the error
|
||||||
library: u8,
|
library: String,
|
||||||
/// The function reporting the error
|
/// The function reporting the error
|
||||||
function: u16,
|
function: String,
|
||||||
/// The reason for the error
|
/// The reason for the error
|
||||||
reason: u16
|
reason: String
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_lib(err: c_ulong) -> u8 {
|
fn get_lib(err: c_ulong) -> String {
|
||||||
((err >> 24) & 0xff) as u8
|
unsafe { CString::new(ffi::ERR_lib_error_string(err), false) }.to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_func(err: c_ulong) -> u16 {
|
fn get_func(err: c_ulong) -> String {
|
||||||
((err >> 12) & 0xfff) as u16
|
unsafe { CString::new(ffi::ERR_func_error_string(err), false).to_string() }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_reason(err: c_ulong) -> u16 {
|
fn get_reason(err: c_ulong) -> String {
|
||||||
(err & 0xfff) as u16
|
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 {
|
impl SslError {
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,8 @@ fn init() {
|
||||||
unsafe {
|
unsafe {
|
||||||
INIT.doit(|| {
|
INIT.doit(|| {
|
||||||
ffi::SSL_library_init();
|
ffi::SSL_library_init();
|
||||||
|
ffi::SSL_load_error_strings();
|
||||||
|
ffi::ERR_load_crypto_strings();
|
||||||
let verify_idx = ffi::SSL_CTX_get_ex_new_index(0, ptr::null(), None,
|
let verify_idx = ffi::SSL_CTX_get_ex_new_index(0, ptr::null(), None,
|
||||||
None, None);
|
None, None);
|
||||||
assert!(verify_idx >= 0);
|
assert!(verify_idx >= 0);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue