@@ -119,3 +119,57 @@ pub const PARSEC_PROVIDER_SIGNATURE: [OSSL_ALGORITHM; 3] = [
119119 ) ,
120120 ossl_algorithm ! ( ) ,
121121] ;
122+
123+ #[ test]
124+ fn test_sign_dup ( ) {
125+ use crate :: parsec_provider_provider_init;
126+
127+ let out: * const OSSL_DISPATCH = std:: ptr:: null ( ) ;
128+ let mut provctx: types:: VOID_PTR = std:: ptr:: null_mut ( ) ;
129+
130+ // Initialize the provider
131+ let result: Result < ( ) , parsec_openssl2:: Error > = unsafe {
132+ parsec_provider_provider_init (
133+ std:: ptr:: null ( ) ,
134+ std:: ptr:: null ( ) ,
135+ & out as * const _ as * mut _ ,
136+ & mut provctx as * mut VOID_PTR ,
137+ )
138+ } ;
139+ assert ! ( result. is_ok( ) ) ;
140+ assert_ne ! ( provctx, std:: ptr:: null_mut( ) ) ;
141+ let s = String :: from ( "" ) ;
142+
143+ let sig_ctx = unsafe { parsec_provider_signature_newctx ( provctx, s. as_ptr ( ) as _ ) } ;
144+ assert_ne ! ( sig_ctx, std:: ptr:: null_mut( ) ) ;
145+
146+ /*
147+ Change the Signature Context.
148+ The way we change it doesn't really matter.
149+ All we care about is whether this change is preserved after duplication.
150+ For this test, we are just changing the key_name of the Signature Context's Key Object.
151+ */
152+ let arc_sig_ctx = unsafe { Arc :: from_raw ( sig_ctx as * const ParsecProviderSignatureContext ) } ;
153+ * ( arc_sig_ctx. keyobj . get_key_name ( ) ) = Some ( "PARSEC_TEST_KEYNAME" . to_string ( ) ) ;
154+
155+ // We change back to using pointers instead of Arcs so that we use the provider functions
156+ let sig_ctx = Arc :: into_raw ( arc_sig_ctx) as VOID_PTR ;
157+
158+ // Duplicate the context and verify if the change is preserved on the duplicated context.
159+ let duplicated_ptr = unsafe { parsec_provider_signature_dupctx ( sig_ctx) } ;
160+ assert_ne ! ( duplicated_ptr, std:: ptr:: null_mut( ) ) ;
161+
162+ let arc_duplicated =
163+ unsafe { Arc :: from_raw ( duplicated_ptr as * const ParsecProviderSignatureContext ) } ;
164+ assert_eq ! (
165+ * ( arc_duplicated. clone( ) . keyobj. clone( ) . get_key_name( ) ) ,
166+ Some ( "PARSEC_TEST_KEYNAME" . to_string( ) )
167+ ) ;
168+
169+ // We change back to using pointers instead of Arcs to use the provider's free
170+ let duplicated_ptr = Arc :: into_raw ( arc_duplicated) as VOID_PTR ;
171+ unsafe {
172+ parsec_provider_signature_freectx ( duplicated_ptr) ;
173+ parsec_provider_signature_freectx ( sig_ctx) ;
174+ }
175+ }
0 commit comments