From bca9a53c66c967affb8e245f26507494db39c35e Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Thu, 15 Jan 2015 22:22:20 +0530 Subject: [PATCH] feat(net): Move SSL verification to unboxed closures --- src/client/mod.rs | 6 +++--- src/net.rs | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/client/mod.rs b/src/client/mod.rs index 5853c067d9..43befdbca8 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -47,15 +47,15 @@ pub struct Client { redirect_policy: RedirectPolicy, } -impl Client { +impl<'v> Client> { /// Create a new Client. - pub fn new() -> Client { + pub fn new() -> Client> { 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)); } diff --git a/src/net.rs b/src/net.rs index 9753613469..8d4dea9172 100644 --- a/src/net.rs +++ b/src/net.rs @@ -309,12 +309,12 @@ impl NetworkStream for HttpStream { /// A connector that will produce HttpStreams. #[allow(missing_copy_implementations)] -pub struct HttpConnector(pub Option); +pub struct HttpConnector<'v>(pub Option>); /// 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 ()+'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 { @@ -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));