Skip to content

Commit 46509a9

Browse files
committed
Add PkeyCtx::new_from_name
1 parent 10cee24 commit 46509a9

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

openssl-sys/src/handwritten/evp.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,11 @@ extern "C" {
511511

512512
pub fn EVP_PKEY_CTX_new(k: *mut EVP_PKEY, e: *mut ENGINE) -> *mut EVP_PKEY_CTX;
513513
pub fn EVP_PKEY_CTX_new_id(id: c_int, e: *mut ENGINE) -> *mut EVP_PKEY_CTX;
514+
pub fn EVP_PKEY_CTX_new_from_name(
515+
ctx: *mut OSSL_LIB_CTX,
516+
name: *const c_char,
517+
property: *const c_char,
518+
) -> *mut EVP_PKEY_CTX;
514519
pub fn EVP_PKEY_CTX_free(ctx: *mut EVP_PKEY_CTX);
515520

516521
pub fn EVP_PKEY_CTX_ctrl(

openssl/src/pkey_ctx.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ use foreign_types::{ForeignType, ForeignTypeRef};
7777
use libc::c_int;
7878
use openssl_macros::corresponds;
7979
use std::convert::TryFrom;
80+
use std::ffi::CString;
8081
use std::ptr;
8182

8283
/// HKDF modes of operation.
@@ -125,6 +126,24 @@ impl<T> PkeyCtx<T> {
125126
Ok(PkeyCtx::from_ptr(ptr))
126127
}
127128
}
129+
130+
#[cfg(ossl300)]
131+
pub fn new_from_name(
132+
lib_ctx: &crate::lib_ctx::LibCtxRef,
133+
name: &str,
134+
property: Option<&str>,
135+
) -> Result<Self, ErrorStack> {
136+
unsafe {
137+
let property = property.map(|s| CString::new(s).unwrap());
138+
let name = CString::new(name).unwrap();
139+
let ptr = cvt_p(ffi::EVP_PKEY_CTX_new_from_name(
140+
lib_ctx.as_ptr(),
141+
name.as_ptr(),
142+
property.map_or(ptr::null_mut(), |s| s.as_ptr()),
143+
))?;
144+
Ok(PkeyCtx::from_ptr(ptr))
145+
}
146+
}
128147
}
129148

130149
impl PkeyCtx<()> {
@@ -999,4 +1018,14 @@ mod test {
9991018
// The digest is the end of the DigestInfo structure.
10001019
assert_eq!(result_buf[length - digest.len()..length], digest);
10011020
}
1021+
1022+
#[test]
1023+
#[cfg(ossl300)]
1024+
fn test_pkeyctx_from_name() {
1025+
use crate::pkey::Public;
1026+
1027+
let lib_ctx = crate::lib_ctx::LibCtx::new().unwrap();
1028+
let _: PkeyCtx<Public> =
1029+
PkeyCtx::new_from_name(lib_ctx.as_ref(), "RSA", None).unwrap();
1030+
}
10021031
}

0 commit comments

Comments
 (0)