diff options
| author | johnthagen <[email protected]> | 2017-10-03 17:44:02 -0400 |
|---|---|---|
| committer | johnthagen <[email protected]> | 2017-10-03 17:44:02 -0400 |
| commit | b5bb8de4f2bd18735346a6062a13d95bcf82bdee (patch) | |
| tree | 11a6f6d11bc412fc89a4bfb3517ced56bf047012 /openssl/src/ssl | |
| parent | Merge pull request #743 from AndyGauge/doc-asn1 (diff) | |
| download | rust-openssl-b5bb8de4f2bd18735346a6062a13d95bcf82bdee.tar.xz rust-openssl-b5bb8de4f2bd18735346a6062a13d95bcf82bdee.zip | |
Convert try! usage to ?
Diffstat (limited to 'openssl/src/ssl')
| -rw-r--r-- | openssl/src/ssl/bio.rs | 2 | ||||
| -rw-r--r-- | openssl/src/ssl/connector.rs | 54 | ||||
| -rw-r--r-- | openssl/src/ssl/error.rs | 10 | ||||
| -rw-r--r-- | openssl/src/ssl/mod.rs | 28 |
4 files changed, 47 insertions, 47 deletions
diff --git a/openssl/src/ssl/bio.rs b/openssl/src/ssl/bio.rs index 86a055a5..4b792a75 100644 --- a/openssl/src/ssl/bio.rs +++ b/openssl/src/ssl/bio.rs @@ -40,7 +40,7 @@ pub fn new<S: Read + Write>(stream: S) -> Result<(*mut BIO, BioMethod), ErrorSta }); unsafe { - let bio = try!(cvt_p(BIO_new(method.0.get()))); + let bio = cvt_p(BIO_new(method.0.get()))?; compat::BIO_set_data(bio, Box::into_raw(state) as *mut _); compat::BIO_set_init(bio, 1); diff --git a/openssl/src/ssl/connector.rs b/openssl/src/ssl/connector.rs index 076f246f..e337b16e 100644 --- a/openssl/src/ssl/connector.rs +++ b/openssl/src/ssl/connector.rs @@ -26,7 +26,7 @@ ssbzSibBsu/6iGtCOGEoXJf//////////wIBAg== "; fn ctx(method: SslMethod) -> Result<SslContextBuilder, ErrorStack> { - let mut ctx = try!(SslContextBuilder::new(method)); + let mut ctx = SslContextBuilder::new(method)?; let mut opts = ssl::SSL_OP_ALL; opts &= !ssl::SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG; @@ -64,16 +64,16 @@ impl SslConnectorBuilder { /// /// The default configuration is subject to change, and is currently derived from Python. pub fn new(method: SslMethod) -> Result<SslConnectorBuilder, ErrorStack> { - let mut ctx = try!(ctx(method)); - try!(ctx.set_default_verify_paths()); + let mut ctx = ctx(method)?; + ctx.set_default_verify_paths()?; // From https://github.com/python/cpython/blob/a170fa162dc03f0a014373349e548954fff2e567/Lib/ssl.py#L193 - try!(ctx.set_cipher_list( + ctx.set_cipher_list( "TLS13-AES-256-GCM-SHA384:TLS13-CHACHA20-POLY1305-SHA256:\ TLS13-AES-128-GCM-SHA256:\ ECDH+AESGCM:ECDH+CHACHA20:DH+AESGCM:DH+CHACHA20:ECDH+AES256:DH+AES256:\ ECDH+AES128:DH+AES:ECDH+HIGH:DH+HIGH:RSA+AESGCM:RSA+AES:RSA+HIGH:\ !aNULL:!eNULL:!MD5:!3DES" - )); + )?; setup_verify(&mut ctx); Ok(SslConnectorBuilder(ctx)) @@ -113,7 +113,7 @@ impl SslConnector { where S: Read + Write, { - try!(self.configure()).connect(domain, stream) + self.configure()?.connect(domain, stream) } /// Initiates a client-side TLS session on a stream without performing hostname verification. @@ -127,7 +127,7 @@ impl SslConnector { &self, stream: S) -> Result<SslStream<S>, HandshakeError<S>> where S: Read + Write { - try!(self.configure()) + self.configure()? .danger_connect_without_providing_domain_for_certificate_verification_and_server_name_indication(stream) } @@ -158,8 +158,8 @@ impl ConnectConfiguration { where S: Read + Write, { - try!(self.0.set_hostname(domain)); - try!(setup_verify_hostname(&mut self.0, domain)); + self.0.set_hostname(domain)?; + setup_verify_hostname(&mut self.0, domain)?; self.0.connect(stream) } @@ -202,7 +202,7 @@ impl SslAcceptorBuilder { I: IntoIterator, I::Item: AsRef<X509Ref>, { - let builder = try!(SslAcceptorBuilder::mozilla_intermediate_raw(method)); + let builder = SslAcceptorBuilder::mozilla_intermediate_raw(method)?; builder.finish_setup(private_key, certificate, chain) } @@ -222,17 +222,17 @@ impl SslAcceptorBuilder { I: IntoIterator, I::Item: AsRef<X509Ref>, { - let builder = try!(SslAcceptorBuilder::mozilla_modern_raw(method)); + let builder = SslAcceptorBuilder::mozilla_modern_raw(method)?; builder.finish_setup(private_key, certificate, chain) } /// Like `mozilla_intermediate`, but does not load the certificate chain and private key. pub fn mozilla_intermediate_raw(method: SslMethod) -> Result<SslAcceptorBuilder, ErrorStack> { - let mut ctx = try!(ctx(method)); - let dh = try!(Dh::from_pem(DHPARAM_PEM.as_bytes())); - try!(ctx.set_tmp_dh(&dh)); - try!(setup_curves(&mut ctx)); - try!(ctx.set_cipher_list( + let mut ctx = ctx(method)?; + let dh = Dh::from_pem(DHPARAM_PEM.as_bytes())?; + ctx.set_tmp_dh(&dh)?; + setup_curves(&mut ctx)?; + ctx.set_cipher_list( "ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:\ ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:\ ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:\ @@ -243,20 +243,20 @@ impl SslAcceptorBuilder { DHE-RSA-AES256-SHA:ECDHE-ECDSA-DES-CBC3-SHA:ECDHE-RSA-DES-CBC3-SHA:\ EDH-RSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:\ AES128-SHA:AES256-SHA:DES-CBC3-SHA:!DSS", - )); + )?; Ok(SslAcceptorBuilder(ctx)) } /// Like `mozilla_modern`, but does not load the certificate chain and private key. pub fn mozilla_modern_raw(method: SslMethod) -> Result<SslAcceptorBuilder, ErrorStack> { - let mut ctx = try!(ctx(method)); - try!(setup_curves(&mut ctx)); - try!(ctx.set_cipher_list( + let mut ctx = ctx(method)?; + setup_curves(&mut ctx)?; + ctx.set_cipher_list( "ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:\ ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:\ ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:\ ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256", - )); + )?; Ok(SslAcceptorBuilder(ctx)) } @@ -270,11 +270,11 @@ impl SslAcceptorBuilder { I: IntoIterator, I::Item: AsRef<X509Ref>, { - try!(self.0.set_private_key(private_key)); - try!(self.0.set_certificate(certificate)); - try!(self.0.check_private_key()); + self.0.set_private_key(private_key)?; + self.0.set_certificate(certificate)?; + self.0.check_private_key()?; for cert in chain { - try!(self.0.add_extra_chain_cert(cert.as_ref().to_owned())); + self.0.add_extra_chain_cert(cert.as_ref().to_owned())?; } Ok(self) } @@ -300,7 +300,7 @@ fn setup_curves(ctx: &mut SslContextBuilder) -> Result<(), ErrorStack> { use ec::EcKey; use nid; - let curve = try!(EcKey::from_curve_name(nid::X9_62_PRIME256V1)); + let curve = EcKey::from_curve_name(nid::X9_62_PRIME256V1)?; ctx.set_tmp_ecdh(&curve) } @@ -327,7 +327,7 @@ impl SslAcceptor { where S: Read + Write, { - let ssl = try!(Ssl::new(&self.0)); + let ssl = Ssl::new(&self.0)?; ssl.accept(stream) } } diff --git a/openssl/src/ssl/error.rs b/openssl/src/ssl/error.rs index 74782d7a..db78e2c8 100644 --- a/openssl/src/ssl/error.rs +++ b/openssl/src/ssl/error.rs @@ -28,7 +28,7 @@ pub enum Error { impl fmt::Display for Error { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { - try!(fmt.write_str(self.description())); + fmt.write_str(self.description())?; if let Some(err) = self.cause() { write!(fmt, ": {}", err) } else { @@ -98,14 +98,14 @@ impl<S: Any + fmt::Debug> StdError for HandshakeError<S> { impl<S: Any + fmt::Debug> fmt::Display for HandshakeError<S> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - try!(f.write_str(StdError::description(self))); + f.write_str(StdError::description(self))?; match *self { - HandshakeError::SetupFailure(ref e) => try!(write!(f, ": {}", e)), + HandshakeError::SetupFailure(ref e) => write!(f, ": {}", e)?, HandshakeError::Failure(ref s) | HandshakeError::Interrupted(ref s) => { - try!(write!(f, ": {}", s.error())); + write!(f, ": {}", s.error())?; if let Some(err) = s.ssl().verify_result() { - try!(write!(f, ": {}", err)); + write!(f, ": {}", err)?; } } } diff --git a/openssl/src/ssl/mod.rs b/openssl/src/ssl/mod.rs index 762118a5..972d583e 100644 --- a/openssl/src/ssl/mod.rs +++ b/openssl/src/ssl/mod.rs @@ -343,7 +343,7 @@ impl SslContextBuilder { pub fn new(method: SslMethod) -> Result<SslContextBuilder, ErrorStack> { unsafe { init(); - let ctx = try!(cvt_p(ffi::SSL_CTX_new(method.as_ptr()))); + let ctx = cvt_p(ffi::SSL_CTX_new(method.as_ptr()))?; Ok(SslContextBuilder::from_ptr(ctx)) } @@ -416,10 +416,10 @@ impl SslContextBuilder { pub fn set_verify_cert_store(&mut self, cert_store: X509Store) -> Result<(), ErrorStack> { unsafe { let ptr = cert_store.as_ptr(); - try!(cvt( + cvt( ffi::SSL_CTX_set0_verify_cert_store(self.as_ptr(), ptr) as c_int, - )); + )?; mem::forget(cert_store); Ok(()) @@ -579,10 +579,10 @@ impl SslContextBuilder { /// `set_certificate` to a trusted root. pub fn add_extra_chain_cert(&mut self, cert: X509) -> Result<(), ErrorStack> { unsafe { - try!(cvt(ffi::SSL_CTX_add_extra_chain_cert( + cvt(ffi::SSL_CTX_add_extra_chain_cert( self.as_ptr(), cert.as_ptr(), - ) as c_int)); + ) as c_int)?; mem::forget(cert); Ok(()) } @@ -661,11 +661,11 @@ impl SslContextBuilder { unsafe { // Attach the protocol list to the OpenSSL context structure, // so that we can refer to it within the callback. - try!(cvt(ffi::SSL_CTX_set_ex_data( + cvt(ffi::SSL_CTX_set_ex_data( self.as_ptr(), *NPN_PROTOS_IDX, Box::into_raw(protocols) as *mut c_void, - ))); + ))?; // Now register the callback that performs the default protocol // matching based on the client-supported list of protocols that // has been saved. @@ -712,11 +712,11 @@ impl SslContextBuilder { // ssl ctx's ex_data so that we can configure a function to free it later. In the // future, it might make sense to pull this into our internal struct Ssl instead of // leaning on openssl and using function pointers. - try!(cvt(ffi::SSL_CTX_set_ex_data( + cvt(ffi::SSL_CTX_set_ex_data( self.as_ptr(), *ALPN_PROTOS_IDX, Box::into_raw(protocols) as *mut c_void, - ))); + ))?; // Now register the callback that performs the default protocol // matching based on the client-supported list of protocols that @@ -859,7 +859,7 @@ impl SslContext { { unsafe { ffi::init(); - let idx = try!(cvt_n(compat::get_new_idx(free_data_box::<T>))); + let idx = cvt_n(compat::get_new_idx(free_data_box::<T>))?; Ok(Index::from_raw(idx)) } } @@ -1088,7 +1088,7 @@ impl Ssl { { unsafe { ffi::init(); - let idx = try!(cvt_n(compat::get_new_ssl_idx(free_data_box::<T>))); + let idx = cvt_n(compat::get_new_ssl_idx(free_data_box::<T>))?; Ok(Index::from_raw(idx)) } } @@ -1484,11 +1484,11 @@ impl SslRef { pub fn set_ocsp_status(&mut self, response: &[u8]) -> Result<(), ErrorStack> { unsafe { assert!(response.len() <= c_int::max_value() as usize); - let p = try!(cvt_p(ffi::CRYPTO_malloc( + let p = cvt_p(ffi::CRYPTO_malloc( response.len() as _, concat!(file!(), "\0").as_ptr() as *const _, line!() as c_int, - ))); + ))?; ptr::copy_nonoverlapping(response.as_ptr(), p as *mut u8, response.len()); cvt(ffi::SSL_set_tlsext_status_ocsp_resp( self.as_ptr(), @@ -1540,7 +1540,7 @@ impl fmt::Debug for Ssl { impl Ssl { pub fn new(ctx: &SslContext) -> Result<Ssl, ErrorStack> { unsafe { - let ssl = try!(cvt_p(ffi::SSL_new(ctx.as_ptr()))); + let ssl = cvt_p(ffi::SSL_new(ctx.as_ptr()))?; Ok(Ssl::from_ptr(ssl)) } } |