Skip to content

Commit

Permalink
feat(net): Move SSL verification to unboxed closures
Browse files Browse the repository at this point in the history
  • Loading branch information
Manishearth committed Jan 15, 2015
1 parent af57785 commit bca9a53
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ pub struct Client<C> {
redirect_policy: RedirectPolicy,
}

impl Client<HttpConnector> {
impl<'v> Client<HttpConnector<'v>> {

/// Create a new Client.
pub fn new() -> Client<HttpConnector> {
pub fn new() -> Client<HttpConnector<'v>> {
Client::with_connector(HttpConnector(None))
}

/// Set the SSL verifier callback for use with OpenSSL.
pub fn set_ssl_verifier(&mut self, verifier: ContextVerifier) {
pub fn set_ssl_verifier(&mut self, verifier: ContextVerifier<'v>) {
self.connector = HttpConnector(Some(verifier));
}

Expand Down
10 changes: 5 additions & 5 deletions src/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,12 +309,12 @@ impl NetworkStream for HttpStream {

/// A connector that will produce HttpStreams.
#[allow(missing_copy_implementations)]
pub struct HttpConnector(pub Option<ContextVerifier>);
pub struct HttpConnector<'v>(pub Option<ContextVerifier<'v>>);

/// A method that can set verification methods on an SSL context
pub type ContextVerifier = for <'a> fn(&'a mut SslContext) -> ();
pub type ContextVerifier<'v> = Box<FnMut(&mut SslContext) -> ()+'v>;

impl NetworkConnector for HttpConnector {
impl<'v> NetworkConnector for HttpConnector<'v> {
type Stream = HttpStream;

fn connect(&mut self, host: &str, port: Port, scheme: &str) -> IoResult<HttpStream> {
Expand All @@ -328,8 +328,8 @@ impl NetworkConnector for HttpConnector {
debug!("https scheme");
let stream = try!(TcpStream::connect(addr));
let mut context = try!(SslContext::new(Sslv23).map_err(lift_ssl_error));
if let Some(ref v) = self.0 {
v(&mut context);
if let Some(ref mut verifier) = self.0 {
verifier(&mut context);
}
let ssl = try!(Ssl::new(&context).map_err(lift_ssl_error));
try!(ssl.set_hostname(host).map_err(lift_ssl_error));
Expand Down

0 comments on commit bca9a53

Please sign in to comment.