@@ -491,6 +491,26 @@ ossl_pkey_initialize(VALUE self)
491
491
return self ;
492
492
}
493
493
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
+
494
514
/*
495
515
* call-seq:
496
516
* pkey.oid -> string
@@ -1468,6 +1488,11 @@ Init_ossl_pkey(void)
1468
1488
1469
1489
rb_define_alloc_func (cPKey , ossl_pkey_alloc );
1470
1490
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
1471
1496
rb_define_method (cPKey , "oid" , ossl_pkey_oid , 0 );
1472
1497
rb_define_method (cPKey , "inspect" , ossl_pkey_inspect , 0 );
1473
1498
rb_define_method (cPKey , "to_text" , ossl_pkey_to_text , 0 );
0 commit comments