Commit fc9f10d4 authored by Steven Fackler's avatar Steven Fackler Committed by GitHub
Browse files

Merge pull request #750 from johnthagen/remove-try

Convert try! usage to ?
parents 7159215e b5bb8de4
Loading
Loading
Loading
Loading
+7 −7
Original line number Diff line number Diff line
@@ -63,11 +63,11 @@ foreign_type! {
impl fmt::Display for Asn1GeneralizedTimeRef {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        unsafe {
            let mem_bio = try!(MemBio::new());
            try!(cvt(ffi::ASN1_GENERALIZEDTIME_print(
            let mem_bio = MemBio::new()?;
            cvt(ffi::ASN1_GENERALIZEDTIME_print(
                mem_bio.as_ptr(),
                self.as_ptr(),
            )));
            ))?;
            write!(f, "{}", str::from_utf8_unchecked(mem_bio.get_buf()))
        }
    }
@@ -96,8 +96,8 @@ foreign_type! {
impl fmt::Display for Asn1TimeRef {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        unsafe {
            let mem_bio = try!(MemBio::new());
            try!(cvt(ffi::ASN1_TIME_print(mem_bio.as_ptr(), self.as_ptr())));
            let mem_bio = MemBio::new()?;
            cvt(ffi::ASN1_TIME_print(mem_bio.as_ptr(), self.as_ptr()))?;
            write!(f, "{}", str::from_utf8_unchecked(mem_bio.get_buf()))
        }
    }
@@ -108,7 +108,7 @@ impl Asn1Time {
        ffi::init();

        unsafe {
            let handle = try!(cvt_p(ffi::X509_gmtime_adj(ptr::null_mut(), period)));
            let handle = cvt_p(ffi::X509_gmtime_adj(ptr::null_mut(), period))?;
            Ok(Asn1Time::from_ptr(handle))
        }
    }
@@ -279,7 +279,7 @@ impl fmt::Display for Asn1ObjectRef {
                self.as_ptr(),
                0,
            );
            let s = try!(str::from_utf8(&buf[..len as usize]).map_err(|_| fmt::Error));
            let s = str::from_utf8(&buf[..len as usize]).map_err(|_| fmt::Error)?;
            fmt.write_str(s)
        }
    }
+3 −3
Original line number Diff line number Diff line
@@ -23,10 +23,10 @@ impl<'a> MemBioSlice<'a> {

        assert!(buf.len() <= c_int::max_value() as usize);
        let bio = unsafe {
            try!(cvt_p(BIO_new_mem_buf(
            cvt_p(BIO_new_mem_buf(
                buf.as_ptr() as *const _,
                buf.len() as c_int,
            )))
            ))?
        };

        Ok(MemBioSlice(bio, PhantomData))
@@ -51,7 +51,7 @@ impl MemBio {
    pub fn new() -> Result<MemBio, ErrorStack> {
        ffi::init();

        let bio = unsafe { try!(cvt_p(ffi::BIO_new(ffi::BIO_s_mem()))) };
        let bio = unsafe { cvt_p(ffi::BIO_new(ffi::BIO_s_mem()))? };
        Ok(MemBio(bio))
    }

+5 −5
Original line number Diff line number Diff line
@@ -589,7 +589,7 @@ impl BigNumRef {
    /// ```
    pub fn to_dec_str(&self) -> Result<OpensslString, ErrorStack> {
        unsafe {
            let buf = try!(cvt_p(ffi::BN_bn2dec(self.as_ptr())));
            let buf = cvt_p(ffi::BN_bn2dec(self.as_ptr()))?;
            Ok(OpensslString::from_ptr(buf))
        }
    }
@@ -604,7 +604,7 @@ impl BigNumRef {
    /// ```
    pub fn to_hex_str(&self) -> Result<OpensslString, ErrorStack> {
        unsafe {
            let buf = try!(cvt_p(ffi::BN_bn2hex(self.as_ptr())));
            let buf = cvt_p(ffi::BN_bn2hex(self.as_ptr()))?;
            Ok(OpensslString::from_ptr(buf))
        }
    }
@@ -631,7 +631,7 @@ impl BigNum {
    pub fn new() -> Result<BigNum, ErrorStack> {
        unsafe {
            ffi::init();
            let v = try!(cvt_p(ffi::BN_new()));
            let v = cvt_p(ffi::BN_new())?;
            Ok(BigNum::from_ptr(v))
        }
    }
@@ -649,7 +649,7 @@ impl BigNum {
            ffi::init();
            let c_str = CString::new(s.as_bytes()).unwrap();
            let mut bn = ptr::null_mut();
            try!(cvt(ffi::BN_dec2bn(&mut bn, c_str.as_ptr() as *const _)));
            cvt(ffi::BN_dec2bn(&mut bn, c_str.as_ptr() as *const _))?;
            Ok(BigNum::from_ptr(bn))
        }
    }
@@ -660,7 +660,7 @@ impl BigNum {
            ffi::init();
            let c_str = CString::new(s.as_bytes()).unwrap();
            let mut bn = ptr::null_mut();
            try!(cvt(ffi::BN_hex2bn(&mut bn, c_str.as_ptr() as *const _)));
            cvt(ffi::BN_hex2bn(&mut bn, c_str.as_ptr() as *const _))?;
            Ok(BigNum::from_ptr(bn))
        }
    }
+6 −6
Original line number Diff line number Diff line
@@ -26,17 +26,17 @@ impl CmsContentInfoRef {
        unsafe {
            let pkey = pkey.as_ptr();
            let cert = cert.as_ptr();
            let out = try!(MemBio::new());
            let out = MemBio::new()?;
            let flags: u32 = 0;

            try!(cvt(ffi::CMS_decrypt(
            cvt(ffi::CMS_decrypt(
                self.as_ptr(),
                pkey,
                cert,
                ptr::null_mut(),
                out.as_ptr(),
                flags.into(),
            )));
            ))?;

            Ok(out.get_buf().to_owned())
        }
@@ -47,12 +47,12 @@ impl CmsContentInfoRef {
impl CmsContentInfo {
    pub fn smime_read_cms(smime: &[u8]) -> Result<CmsContentInfo, ErrorStack> {
        unsafe {
            let bio = try!(MemBioSlice::new(smime));
            let bio = MemBioSlice::new(smime)?;

            let cms = try!(cvt_p(ffi::SMIME_read_CMS(
            let cms = cvt_p(ffi::SMIME_read_CMS(
                bio.as_ptr(),
                ptr::null_mut(),
            )));
            ))?;

            Ok(CmsContentInfo::from_ptr(cms))
        }
+3 −3
Original line number Diff line number Diff line
@@ -24,13 +24,13 @@ impl DhRef {
impl Dh {
    pub fn from_params(p: BigNum, g: BigNum, q: BigNum) -> Result<Dh, ErrorStack> {
        unsafe {
            let dh = Dh(try!(cvt_p(ffi::DH_new())));
            try!(cvt(compat::DH_set0_pqg(
            let dh = Dh(cvt_p(ffi::DH_new())?);
            cvt(compat::DH_set0_pqg(
                dh.0,
                p.as_ptr(),
                q.as_ptr(),
                g.as_ptr(),
            )));
            ))?;
            mem::forget((p, g, q));
            Ok(dh)
        }
Loading