summaryrefslogtreecommitdiff
path: root/openssl/src/pkey.rs
diff options
context:
space:
mode:
authorjohnthagen <johnthagen@gmail.com>2017-10-03 17:44:02 -0400
committerjohnthagen <johnthagen@gmail.com>2017-10-03 17:44:02 -0400
commitb5bb8de4f2bd18735346a6062a13d95bcf82bdee (patch)
tree11a6f6d11bc412fc89a4bfb3517ced56bf047012 /openssl/src/pkey.rs
parent7159215e45b8ddd7d423f9fd2b8c37a4cbb90563 (diff)
downloadrust-openssl-b5bb8de4f2bd18735346a6062a13d95bcf82bdee.zip
Convert try! usage to ?
Diffstat (limited to 'openssl/src/pkey.rs')
-rw-r--r--openssl/src/pkey.rs70
1 files changed, 35 insertions, 35 deletions
diff --git a/openssl/src/pkey.rs b/openssl/src/pkey.rs
index aba52ae6..f4e36892 100644
--- a/openssl/src/pkey.rs
+++ b/openssl/src/pkey.rs
@@ -26,7 +26,7 @@ impl PKeyRef {
/// Returns a copy of the internal RSA key.
pub fn rsa(&self) -> Result<Rsa, ErrorStack> {
unsafe {
- let rsa = try!(cvt_p(ffi::EVP_PKEY_get1_RSA(self.as_ptr())));
+ let rsa = cvt_p(ffi::EVP_PKEY_get1_RSA(self.as_ptr()))?;
Ok(Rsa::from_ptr(rsa))
}
}
@@ -34,7 +34,7 @@ impl PKeyRef {
/// Returns a copy of the internal DSA key.
pub fn dsa(&self) -> Result<Dsa, ErrorStack> {
unsafe {
- let dsa = try!(cvt_p(ffi::EVP_PKEY_get1_DSA(self.as_ptr())));
+ let dsa = cvt_p(ffi::EVP_PKEY_get1_DSA(self.as_ptr()))?;
Ok(Dsa::from_ptr(dsa))
}
}
@@ -42,7 +42,7 @@ impl PKeyRef {
/// Returns a copy of the internal DH key.
pub fn dh(&self) -> Result<Dh, ErrorStack> {
unsafe {
- let dh = try!(cvt_p(ffi::EVP_PKEY_get1_DH(self.as_ptr())));
+ let dh = cvt_p(ffi::EVP_PKEY_get1_DH(self.as_ptr()))?;
Ok(Dh::from_ptr(dh))
}
}
@@ -50,7 +50,7 @@ impl PKeyRef {
/// Returns a copy of the internal elliptic curve key.
pub fn ec_key(&self) -> Result<EcKey, ErrorStack> {
unsafe {
- let ec_key = try!(cvt_p(ffi::EVP_PKEY_get1_EC_KEY(self.as_ptr())));
+ let ec_key = cvt_p(ffi::EVP_PKEY_get1_EC_KEY(self.as_ptr()))?;
Ok(EcKey::from_ptr(ec_key))
}
}
@@ -82,13 +82,13 @@ impl PKey {
/// Creates a new `PKey` containing an RSA key.
pub fn from_rsa(rsa: Rsa) -> Result<PKey, ErrorStack> {
unsafe {
- let evp = try!(cvt_p(ffi::EVP_PKEY_new()));
+ let evp = cvt_p(ffi::EVP_PKEY_new())?;
let pkey = PKey(evp);
- try!(cvt(ffi::EVP_PKEY_assign(
+ cvt(ffi::EVP_PKEY_assign(
pkey.0,
ffi::EVP_PKEY_RSA,
rsa.as_ptr() as *mut _,
- )));
+ ))?;
mem::forget(rsa);
Ok(pkey)
}
@@ -97,13 +97,13 @@ impl PKey {
/// Creates a new `PKey` containing a DSA key.
pub fn from_dsa(dsa: Dsa) -> Result<PKey, ErrorStack> {
unsafe {
- let evp = try!(cvt_p(ffi::EVP_PKEY_new()));
+ let evp = cvt_p(ffi::EVP_PKEY_new())?;
let pkey = PKey(evp);
- try!(cvt(ffi::EVP_PKEY_assign(
+ cvt(ffi::EVP_PKEY_assign(
pkey.0,
ffi::EVP_PKEY_DSA,
dsa.as_ptr() as *mut _,
- )));
+ ))?;
mem::forget(dsa);
Ok(pkey)
}
@@ -112,13 +112,13 @@ impl PKey {
/// Creates a new `PKey` containing a Diffie-Hellman key.
pub fn from_dh(dh: Dh) -> Result<PKey, ErrorStack> {
unsafe {
- let evp = try!(cvt_p(ffi::EVP_PKEY_new()));
+ let evp = cvt_p(ffi::EVP_PKEY_new())?;
let pkey = PKey(evp);
- try!(cvt(ffi::EVP_PKEY_assign(
+ cvt(ffi::EVP_PKEY_assign(
pkey.0,
ffi::EVP_PKEY_DH,
dh.as_ptr() as *mut _,
- )));
+ ))?;
mem::forget(dh);
Ok(pkey)
}
@@ -127,13 +127,13 @@ impl PKey {
/// Creates a new `PKey` containing an elliptic curve key.
pub fn from_ec_key(ec_key: EcKey) -> Result<PKey, ErrorStack> {
unsafe {
- let evp = try!(cvt_p(ffi::EVP_PKEY_new()));
+ let evp = cvt_p(ffi::EVP_PKEY_new())?;
let pkey = PKey(evp);
- try!(cvt(ffi::EVP_PKEY_assign(
+ cvt(ffi::EVP_PKEY_assign(
pkey.0,
ffi::EVP_PKEY_EC,
ec_key.as_ptr() as *mut _,
- )));
+ ))?;
mem::forget(ec_key);
Ok(pkey)
}
@@ -146,12 +146,12 @@ impl PKey {
pub fn hmac(key: &[u8]) -> Result<PKey, ErrorStack> {
unsafe {
assert!(key.len() <= c_int::max_value() as usize);
- let key = try!(cvt_p(ffi::EVP_PKEY_new_mac_key(
+ let key = cvt_p(ffi::EVP_PKEY_new_mac_key(
ffi::EVP_PKEY_HMAC,
ptr::null_mut(),
key.as_ptr() as *const _,
key.len() as c_int,
- )));
+ ))?;
Ok(PKey(key))
}
}
@@ -173,7 +173,7 @@ impl PKey {
unsafe {
ffi::init();
let mut cb = CallbackState::new(callback);
- let bio = try!(MemBioSlice::new(der));
+ let bio = MemBioSlice::new(der)?;
cvt_p(ffi::d2i_PKCS8PrivateKey_bio(
bio.as_ptr(),
ptr::null_mut(),
@@ -195,7 +195,7 @@ impl PKey {
) -> Result<PKey, ErrorStack> {
unsafe {
ffi::init();
- let bio = try!(MemBioSlice::new(der));
+ let bio = MemBioSlice::new(der)?;
let passphrase = CString::new(passphrase).unwrap();
cvt_p(ffi::d2i_PKCS8PrivateKey_bio(
bio.as_ptr(),
@@ -213,14 +213,14 @@ impl PKey {
{
ffi::init();
let mut cb = CallbackState::new(pass_cb);
- let mem_bio = try!(MemBioSlice::new(buf));
+ let mem_bio = MemBioSlice::new(buf)?;
unsafe {
- let evp = try!(cvt_p(ffi::PEM_read_bio_PrivateKey(
+ let evp = cvt_p(ffi::PEM_read_bio_PrivateKey(
mem_bio.as_ptr(),
ptr::null_mut(),
Some(invoke_passwd_cb_old::<F>),
&mut cb as *mut _ as *mut c_void,
- )));
+ ))?;
Ok(PKey::from_ptr(evp))
}
}
@@ -240,7 +240,7 @@ unsafe impl Sync for PKeyCtx {}
impl PKeyCtx {
pub fn from_pkey(pkey: &PKeyRef) -> Result<PKeyCtx, ErrorStack> {
unsafe {
- let evp = try!(cvt_p(ffi::EVP_PKEY_CTX_new(pkey.as_ptr(), ptr::null_mut())));
+ let evp = cvt_p(ffi::EVP_PKEY_CTX_new(pkey.as_ptr(), ptr::null_mut()))?;
Ok(PKeyCtx(evp))
}
}
@@ -249,10 +249,10 @@ impl PKeyCtx {
impl PKeyCtxRef {
pub fn set_rsa_padding(&mut self, pad: Padding) -> Result<(), ErrorStack> {
unsafe {
- try!(cvt(ffi::EVP_PKEY_CTX_set_rsa_padding(
+ cvt(ffi::EVP_PKEY_CTX_set_rsa_padding(
self.as_ptr(),
pad.as_raw(),
- )));
+ ))?;
}
Ok(())
}
@@ -260,25 +260,25 @@ impl PKeyCtxRef {
pub fn rsa_padding(&self) -> Result<Padding, ErrorStack> {
let mut pad: c_int = 0;
unsafe {
- try!(cvt(
+ cvt(
ffi::EVP_PKEY_CTX_get_rsa_padding(self.as_ptr(), &mut pad),
- ));
+ )?;
};
Ok(Padding::from_raw(pad))
}
pub fn derive_init(&mut self) -> Result<(), ErrorStack> {
unsafe {
- try!(cvt(ffi::EVP_PKEY_derive_init(self.as_ptr())));
+ cvt(ffi::EVP_PKEY_derive_init(self.as_ptr()))?;
}
Ok(())
}
pub fn derive_set_peer(&mut self, peer: &PKeyRef) -> Result<(), ErrorStack> {
unsafe {
- try!(cvt(
+ cvt(
ffi::EVP_PKEY_derive_set_peer(self.as_ptr(), peer.as_ptr()),
- ));
+ )?;
}
Ok(())
}
@@ -286,20 +286,20 @@ impl PKeyCtxRef {
pub fn derive(&mut self) -> Result<Vec<u8>, ErrorStack> {
let mut len: size_t = 0;
unsafe {
- try!(cvt(ffi::EVP_PKEY_derive(
+ cvt(ffi::EVP_PKEY_derive(
self.as_ptr(),
ptr::null_mut(),
&mut len,
- )));
+ ))?;
}
let mut key = vec![0u8; len];
unsafe {
- try!(cvt(ffi::EVP_PKEY_derive(
+ cvt(ffi::EVP_PKEY_derive(
self.as_ptr(),
key.as_mut_ptr(),
&mut len,
- )));
+ ))?;
}
Ok(key)
}