@@ -69,6 +69,8 @@ use crate::cipher::CipherRef;
6969use crate :: error:: ErrorStack ;
7070use crate :: md:: MdRef ;
7171use crate :: nid:: Nid ;
72+ #[ cfg( ossl320) ]
73+ use crate :: params:: ParamBuilder ;
7274#[ cfg( ossl300) ]
7375use crate :: params:: ParamsRef ;
7476#[ cfg( ossl300) ]
@@ -874,6 +876,14 @@ impl<T> PkeyCtxRef<T> {
874876 }
875877 }
876878
879+ /// Sets parameters on the given context
880+ #[ corresponds( EVP_PKEY_CTX_set_params ) ]
881+ #[ cfg( ossl300) ]
882+ #[ allow( dead_code) ]
883+ fn set_params ( & mut self , params : & ParamsRef < ' _ > ) -> Result < ( ) , ErrorStack > {
884+ cvt ( unsafe { ffi:: EVP_PKEY_CTX_set_params ( self . as_ptr ( ) , params. as_ptr ( ) ) } ) . map ( |_| ( ) )
885+ }
886+
877887 /// Sets the nonce type for a private key context.
878888 ///
879889 /// The nonce for DSA and ECDSA can be either random (the default) or deterministic (as defined by RFC 6979).
@@ -883,17 +893,10 @@ impl<T> PkeyCtxRef<T> {
883893 #[ cfg( ossl320) ]
884894 #[ corresponds( EVP_PKEY_CTX_set_params ) ]
885895 pub fn set_nonce_type ( & mut self , nonce_type : NonceType ) -> Result < ( ) , ErrorStack > {
886- let nonce_field_name = c_str ( b"nonce-type\0 " ) ;
887- let mut nonce_type = nonce_type. 0 ;
888- unsafe {
889- let param_nonce =
890- ffi:: OSSL_PARAM_construct_uint ( nonce_field_name. as_ptr ( ) , & mut nonce_type) ;
891- let param_end = ffi:: OSSL_PARAM_construct_end ( ) ;
892-
893- let params = [ param_nonce, param_end] ;
894- cvt ( ffi:: EVP_PKEY_CTX_set_params ( self . as_ptr ( ) , params. as_ptr ( ) ) ) ?;
895- }
896- Ok ( ( ) )
896+ let params = ParamBuilder :: new ( )
897+ . push_uint ( c_str ( b"nonce-type\0 " ) , nonce_type. 0 ) ?
898+ . build ( ) ?;
899+ self . set_params ( & params)
897900 }
898901
899902 /// Gets the nonce type for a private key context.
0 commit comments