@@ -491,6 +491,26 @@ ossl_pkey_initialize(VALUE self)
491491 return self ;
492492}
493493
494+ #ifdef HAVE_EVP_PKEY_DUP
495+ static VALUE
496+ ossl_pkey_initialize_copy (VALUE self , VALUE other )
497+ {
498+ EVP_PKEY * pkey , * pkey_other ;
499+
500+ TypedData_Get_Struct (self , EVP_PKEY , & ossl_evp_pkey_type , pkey );
501+ TypedData_Get_Struct (other , EVP_PKEY , & ossl_evp_pkey_type , pkey_other );
502+ if (pkey )
503+ rb_raise (rb_eTypeError , "pkey already initialized" );
504+ if (pkey_other ) {
505+ pkey = EVP_PKEY_dup (pkey_other );
506+ if (!pkey )
507+ ossl_raise (ePKeyError , "EVP_PKEY_dup" );
508+ RTYPEDDATA_DATA (self ) = pkey ;
509+ }
510+ return self ;
511+ }
512+ #endif
513+
494514/*
495515 * call-seq:
496516 * pkey.oid -> string
@@ -1468,6 +1488,11 @@ Init_ossl_pkey(void)
14681488
14691489 rb_define_alloc_func (cPKey , ossl_pkey_alloc );
14701490 rb_define_method (cPKey , "initialize" , ossl_pkey_initialize , 0 );
1491+ #ifdef HAVE_EVP_PKEY_DUP
1492+ rb_define_method (cPKey , "initialize_copy" , ossl_pkey_initialize_copy , 1 );
1493+ #else
1494+ rb_undef_method (cPKey , "initialize_copy" );
1495+ #endif
14711496 rb_define_method (cPKey , "oid" , ossl_pkey_oid , 0 );
14721497 rb_define_method (cPKey , "inspect" , ossl_pkey_inspect , 0 );
14731498 rb_define_method (cPKey , "to_text" , ossl_pkey_to_text , 0 );
0 commit comments