@@ -69,6 +69,8 @@ use crate::cipher::CipherRef;
69
69
use crate :: error:: ErrorStack ;
70
70
use crate :: md:: MdRef ;
71
71
use crate :: nid:: Nid ;
72
+ #[ cfg( ossl320) ]
73
+ use crate :: params:: ParamBuilder ;
72
74
#[ cfg( ossl300) ]
73
75
use crate :: params:: ParamsRef ;
74
76
#[ cfg( ossl300) ]
@@ -874,6 +876,14 @@ impl<T> PkeyCtxRef<T> {
874
876
}
875
877
}
876
878
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
+
877
887
/// Sets the nonce type for a private key context.
878
888
///
879
889
/// 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> {
883
893
#[ cfg( ossl320) ]
884
894
#[ corresponds( EVP_PKEY_CTX_set_params ) ]
885
895
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)
897
900
}
898
901
899
902
/// Gets the nonce type for a private key context.
0 commit comments