From dd140f5167071b913ec576cfce56a63544e28104 Mon Sep 17 00:00:00 2001 From: Zolmeister Date: Tue, 29 Jan 2019 12:00:47 -0600 Subject: [PATCH] add Rsa::generate_with_e(bits: u32, e: BigNum) --- openssl/src/rsa.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/openssl/src/rsa.rs b/openssl/src/rsa.rs index 0d8922a7..90bf915e 100644 --- a/openssl/src/rsa.rs +++ b/openssl/src/rsa.rs @@ -613,6 +613,25 @@ impl Rsa { } } + /// Generates a public/private key pair with the specified size. + /// + /// This corresponds to [`RSA_generate_key_ex`]. + /// + /// [`RSA_generate_key_ex`]: https://www.openssl.org/docs/man1.1.0/crypto/RSA_generate_key_ex.html + pub fn generate_with_e(bits: u32, e: &BigNumRef) -> Result, ErrorStack> { + ffi::init(); + unsafe { + let rsa = Rsa::from_ptr(cvt_p(ffi::RSA_new())?); + cvt(ffi::RSA_generate_key_ex( + rsa.0, + bits as c_int, + e.as_ptr(), + ptr::null_mut(), + ))?; + Ok(rsa) + } + } + // FIXME these need to identify input formats private_key_from_pem! { /// Deserializes a private key from a PEM-encoded PKCS#1 RSAPrivateKey structure.