forked from rust-postgres/rust-postgres
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsecurity_framework.rs
More file actions
56 lines (47 loc) · 1.43 KB
/
Copy pathsecurity_framework.rs
File metadata and controls
56 lines (47 loc) · 1.43 KB
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
//! Security Framework support.
pub extern crate security_framework;
use self::security_framework::secure_transport::{SslStream, ClientBuilder};
use tls::{Stream, TlsStream, TlsHandshake};
use std::error::Error;
impl TlsStream for SslStream<Stream> {
fn get_ref(&self) -> &Stream {
self.get_ref()
}
fn get_mut(&mut self) -> &mut Stream {
self.get_mut()
}
}
/// A `TlsHandshake` implementation that uses the Security Framework.
///
/// Requires the `with-security-framework` feature.
#[derive(Debug)]
pub struct SecurityFramework(ClientBuilder);
impl SecurityFramework {
/// Returns a new `SecurityFramework` with default settings.
pub fn new() -> SecurityFramework {
ClientBuilder::new().into()
}
/// Returns a reference to the associated `ClientBuilder`.
pub fn builder(&self) -> &ClientBuilder {
&self.0
}
/// Returns a mutable reference to the associated `ClientBuilder`.
pub fn builder_mut(&mut self) -> &mut ClientBuilder {
&mut self.0
}
}
impl From<ClientBuilder> for SecurityFramework {
fn from(b: ClientBuilder) -> SecurityFramework {
SecurityFramework(b)
}
}
impl TlsHandshake for SecurityFramework {
fn tls_handshake(
&self,
domain: &str,
stream: Stream,
) -> Result<Box<TlsStream>, Box<Error + Send + Sync>> {
let stream = self.0.handshake(domain, stream)?;
Ok(Box::new(stream))
}
}