blob: 5e5479f8b2c62b33300f60a496f2879e460c432f (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
use std::libc::c_ulong;
use super::ffi;
#[deriving(ToStr)]
pub enum SslError {
StreamEof,
SslSessionClosed,
UnknownError {
library: u8,
function: u16,
reason: u16
}
}
fn get_lib(err: c_ulong) -> u8 {
((err >> 24) & 0xff) as u8
}
fn get_func(err: c_ulong) -> u16 {
((err >> 12) & 0xfff) as u16
}
fn get_reason(err: c_ulong) -> u16 {
(err & 0xfff) as u16
}
impl SslError {
pub fn get() -> Option<SslError> {
match unsafe { ffi::ERR_get_error() } {
0 => None,
err => Some(UnknownError {
library: get_lib(err),
function: get_func(err),
reason: get_reason(err)
})
}
}
}
|