diff --git a/openssl-sys/src/handwritten/evp.rs b/openssl-sys/src/handwritten/evp.rs index 96cc814cc2..e1b0c999c1 100644 --- a/openssl-sys/src/handwritten/evp.rs +++ b/openssl-sys/src/handwritten/evp.rs @@ -511,6 +511,11 @@ extern "C" { pub fn EVP_PKEY_CTX_new(k: *mut EVP_PKEY, e: *mut ENGINE) -> *mut EVP_PKEY_CTX; pub fn EVP_PKEY_CTX_new_id(id: c_int, e: *mut ENGINE) -> *mut EVP_PKEY_CTX; + pub fn EVP_PKEY_CTX_new_from_name( + ctx: *mut OSSL_LIB_CTX, + name: *const c_char, + property: *const c_char, + ) -> *mut EVP_PKEY_CTX; pub fn EVP_PKEY_CTX_free(ctx: *mut EVP_PKEY_CTX); pub fn EVP_PKEY_CTX_ctrl( diff --git a/openssl/src/pkey_ctx.rs b/openssl/src/pkey_ctx.rs index 4ac32a8517..22cc54f0d5 100644 --- a/openssl/src/pkey_ctx.rs +++ b/openssl/src/pkey_ctx.rs @@ -77,6 +77,7 @@ use foreign_types::{ForeignType, ForeignTypeRef}; use libc::c_int; use openssl_macros::corresponds; use std::convert::TryFrom; +use std::ffi::CString; use std::ptr; /// HKDF modes of operation. @@ -125,6 +126,24 @@ impl PkeyCtx { Ok(PkeyCtx::from_ptr(ptr)) } } + + #[cfg(ossl300)] + pub fn new_from_name( + lib_ctx: &crate::lib_ctx::LibCtxRef, + name: &str, + property: Option<&str>, + ) -> Result { + unsafe { + let property = property.map(|s| CString::new(s).unwrap()); + let name = CString::new(name).unwrap(); + let ptr = cvt_p(ffi::EVP_PKEY_CTX_new_from_name( + lib_ctx.as_ptr(), + name.as_ptr(), + property.map_or(ptr::null_mut(), |s| s.as_ptr()), + ))?; + Ok(PkeyCtx::from_ptr(ptr)) + } + } } impl PkeyCtx<()> { @@ -999,4 +1018,13 @@ mod test { // The digest is the end of the DigestInfo structure. assert_eq!(result_buf[length - digest.len()..length], digest); } + + #[test] + #[cfg(ossl300)] + fn test_pkeyctx_from_name() { + use crate::pkey::Public; + + let lib_ctx = crate::lib_ctx::LibCtx::new().unwrap(); + let _: PkeyCtx = PkeyCtx::new_from_name(lib_ctx.as_ref(), "RSA", None).unwrap(); + } }