@@ -77,6 +77,7 @@ use foreign_types::{ForeignType, ForeignTypeRef};
77
77
use libc:: c_int;
78
78
use openssl_macros:: corresponds;
79
79
use std:: convert:: TryFrom ;
80
+ use std:: ffi:: CString ;
80
81
use std:: ptr;
81
82
82
83
/// HKDF modes of operation.
@@ -125,6 +126,24 @@ impl<T> PkeyCtx<T> {
125
126
Ok ( PkeyCtx :: from_ptr ( ptr) )
126
127
}
127
128
}
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
+ }
128
147
}
129
148
130
149
impl PkeyCtx < ( ) > {
@@ -999,4 +1018,14 @@ mod test {
999
1018
// The digest is the end of the DigestInfo structure.
1000
1019
assert_eq ! ( result_buf[ length - digest. len( ) ..length] , digest) ;
1001
1020
}
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
+ }
1002
1031
}
0 commit comments