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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
use cassandra::error::CassError;
use cassandra::util::Protected;
use cassandra_sys::CassSsl as _Ssl;
use cassandra_sys::cass_ssl_add_trusted_cert;
use cassandra_sys::cass_ssl_free;
use cassandra_sys::cass_ssl_new;
use cassandra_sys::cass_ssl_set_cert;
use cassandra_sys::cass_ssl_set_private_key;
use cassandra_sys::cass_ssl_set_verify_flags;
use errors::*;
use std::ffi::CString;
#[derive(Debug)]
pub struct Ssl(*mut _Ssl);
impl Protected<*mut _Ssl> for Ssl {
fn inner(&self) -> *mut _Ssl { self.0 }
fn build(inner: *mut _Ssl) -> Self { Ssl(inner) }
}
impl Drop for Ssl {
fn drop(&mut self) { unsafe { cass_ssl_free(self.0) } }
}
impl Default for Ssl {
fn default() -> Ssl { unsafe { Ssl(cass_ssl_new()) } }
}
impl Ssl {
pub fn add_trusted_cert(&mut self, cert: &str) -> Result<&mut Self> {
unsafe {
cass_ssl_add_trusted_cert(self.0, CString::new(cert).expect("must be utf8").as_ptr())
.to_result(self)
.chain_err(|| "")
}
}
pub fn set_verify_flags(&mut self, flags: i32) { unsafe { cass_ssl_set_verify_flags(self.0, flags) } }
pub fn set_cert(&mut self, cert: &str) -> Result<&mut Self> {
unsafe {
cass_ssl_set_cert(self.0, CString::new(cert).expect("must be utf8").as_ptr())
.to_result(self)
.chain_err(|| "")
}
}
pub fn set_private_key(&mut self, key: &str, password: &str) -> Result<&mut Self> {
unsafe {
cass_ssl_set_private_key(self.0,
CString::new(key).expect("must be utf8").as_ptr(),
password.as_ptr() as *const i8)
.to_result(self)
.chain_err(|| "")
}
}
}