From 2e00fb371ba37211a6f779f0a96a4ffb372cf457 Mon Sep 17 00:00:00 2001 From: Nathaniel McCallum Date: Tue, 17 Dec 2019 15:45:35 +0000 Subject: [PATCH] Replace try!() with ? --- openssl/src/macros.rs | 50 +++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/openssl/src/macros.rs b/openssl/src/macros.rs index 3d685484..06e3c019 100644 --- a/openssl/src/macros.rs +++ b/openssl/src/macros.rs @@ -6,7 +6,7 @@ macro_rules! private_key_from_pem { pub fn $n2(pem: &[u8], passphrase: &[u8]) -> Result<$t, ::error::ErrorStack> { unsafe { ffi::init(); - let bio = try!(::bio::MemBioSlice::new(pem)); + let bio = ::bio::MemBioSlice::new(pem)?; let passphrase = ::std::ffi::CString::new(passphrase).unwrap(); cvt_p($f(bio.as_ptr(), ptr::null_mut(), @@ -23,7 +23,7 @@ macro_rules! private_key_from_pem { unsafe { ffi::init(); let mut cb = ::util::CallbackState::new(callback); - let bio = try!(::bio::MemBioSlice::new(pem)); + let bio = ::bio::MemBioSlice::new(pem)?; cvt_p($f(bio.as_ptr(), ptr::null_mut(), Some(::util::invoke_passwd_cb::), @@ -39,14 +39,14 @@ macro_rules! private_key_to_pem { $(#[$m])* pub fn $n(&self) -> Result, ::error::ErrorStack> { unsafe { - let bio = try!(::bio::MemBio::new()); - try!(cvt($f(bio.as_ptr(), - self.as_ptr(), - ptr::null(), - ptr::null_mut(), - -1, - None, - ptr::null_mut()))); + let bio = ::bio::MemBio::new()?; + cvt($f(bio.as_ptr(), + self.as_ptr(), + ptr::null(), + ptr::null_mut(), + -1, + None, + ptr::null_mut()))?; Ok(bio.get_buf().to_owned()) } } @@ -58,15 +58,15 @@ macro_rules! private_key_to_pem { passphrase: &[u8] ) -> Result, ::error::ErrorStack> { unsafe { - let bio = try!(::bio::MemBio::new()); + let bio = ::bio::MemBio::new()?; assert!(passphrase.len() <= ::libc::c_int::max_value() as usize); - try!(cvt($f(bio.as_ptr(), - self.as_ptr(), - cipher.as_ptr(), - passphrase.as_ptr() as *const _ as *mut _, - passphrase.len() as ::libc::c_int, - None, - ptr::null_mut()))); + cvt($f(bio.as_ptr(), + self.as_ptr(), + cipher.as_ptr(), + passphrase.as_ptr() as *const _ as *mut _, + passphrase.len() as ::libc::c_int, + None, + ptr::null_mut()))?; Ok(bio.get_buf().to_owned()) } } @@ -78,8 +78,8 @@ macro_rules! to_pem { $(#[$m])* pub fn $n(&self) -> Result, ::error::ErrorStack> { unsafe { - let bio = try!(::bio::MemBio::new()); - try!(cvt($f(bio.as_ptr(), self.as_ptr()))); + let bio = ::bio::MemBio::new()?; + cvt($f(bio.as_ptr(), self.as_ptr()))?; Ok(bio.get_buf().to_owned()) } } @@ -91,11 +91,11 @@ macro_rules! to_der { $(#[$m])* pub fn $n(&self) -> Result, ::error::ErrorStack> { unsafe { - let len = try!(::cvt($f(::foreign_types::ForeignTypeRef::as_ptr(self), - ptr::null_mut()))); + let len = ::cvt($f(::foreign_types::ForeignTypeRef::as_ptr(self), + ptr::null_mut()))?; let mut buf = vec![0; len as usize]; - try!(::cvt($f(::foreign_types::ForeignTypeRef::as_ptr(self), - &mut buf.as_mut_ptr()))); + ::cvt($f(::foreign_types::ForeignTypeRef::as_ptr(self), + &mut buf.as_mut_ptr()))?; Ok(buf) } } @@ -122,7 +122,7 @@ macro_rules! from_pem { pub fn $n(pem: &[u8]) -> Result<$t, ::error::ErrorStack> { unsafe { ::init(); - let bio = try!(::bio::MemBioSlice::new(pem)); + let bio = ::bio::MemBioSlice::new(pem)?; cvt_p($f(bio.as_ptr(), ::std::ptr::null_mut(), None, ::std::ptr::null_mut())) .map(|p| ::foreign_types::ForeignType::from_ptr(p)) }