From e56e09b6a41770d0e2f15f30fb5851e094101da0 Mon Sep 17 00:00:00 2001 From: Zolmeister Date: Fri, 18 Jan 2019 17:49:42 -0600 Subject: [PATCH] Add RsaRef::check_key --- openssl-sys/src/rsa.rs | 3 +++ openssl/src/rsa.rs | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/openssl-sys/src/rsa.rs b/openssl-sys/src/rsa.rs index 73880c3d..ce806aef 100644 --- a/openssl-sys/src/rsa.rs +++ b/openssl-sys/src/rsa.rs @@ -143,6 +143,9 @@ extern "C" { k: *mut RSA, pad: c_int, ) -> c_int; + pub fn RSA_check_key( + r: *const ::RSA, + ) -> c_int; pub fn RSA_free(rsa: *mut RSA); pub fn RSA_up_ref(rsa: *mut RSA) -> c_int; diff --git a/openssl/src/rsa.rs b/openssl/src/rsa.rs index 631e21ac..0d8922a7 100644 --- a/openssl/src/rsa.rs +++ b/openssl/src/rsa.rs @@ -278,6 +278,22 @@ where } } } + + /// Validates RSA parameters for correctness + /// + /// This corresponds to [`RSA_check_key`]. + /// + /// [`RSA_check_key`]: https://www.openssl.org/docs/man1.1.0/crypto/RSA_check_key.html + pub fn check_key(&self) -> Result { + unsafe { + let result = ffi::RSA_check_key(self.as_ptr()) as i32; + if result == -1 { + Err(ErrorStack::get()) + } else { + Ok(result == 1) + } + } + } } impl RsaRef