@@ -142,11 +142,9 @@ static VALUE ossl_ec_key_initialize(int argc, VALUE *argv, VALUE self)
142142 VALUE arg , pass ;
143143 int type ;
144144
145- TypedData_Get_Struct (self , EVP_PKEY , & ossl_evp_pkey_type , pkey );
146- if (pkey )
147- rb_raise (rb_eTypeError , "pkey already initialized" );
148-
149145 rb_scan_args (argc , argv , "02" , & arg , & pass );
146+ ossl_want_uninitialized (self , & ossl_evp_pkey_type );
147+
150148 if (NIL_P (arg )) {
151149#ifdef OSSL_HAVE_IMMUTABLE_PKEY
152150 rb_raise (rb_eArgError , "OpenSSL::PKey::EC.new cannot be called " \
@@ -202,9 +200,7 @@ ossl_ec_key_initialize_copy(VALUE self, VALUE other)
202200 const EC_KEY * ec ;
203201 EC_KEY * ec_new ;
204202
205- TypedData_Get_Struct (self , EVP_PKEY , & ossl_evp_pkey_type , pkey );
206- if (pkey )
207- rb_raise (rb_eTypeError , "pkey already initialized" );
203+ ossl_want_uninitialized (self , & ossl_evp_pkey_type );
208204 GetEC (other , ec );
209205
210206 ec_new = EC_KEY_dup (ec );
@@ -632,11 +628,10 @@ static VALUE ossl_ec_group_initialize(int argc, VALUE *argv, VALUE self)
632628 VALUE arg1 , arg2 , arg3 , arg4 ;
633629 EC_GROUP * group ;
634630
635- TypedData_Get_Struct (self , EC_GROUP , & ossl_ec_group_type , group );
636- if (group )
637- ossl_raise (rb_eRuntimeError , "EC_GROUP is already initialized" );
631+ rb_scan_args (argc , argv , "13" , & arg1 , & arg2 , & arg3 , & arg4 );
632+ ossl_want_uninitialized (self , & ossl_ec_group_type );
638633
639- switch (rb_scan_args ( argc , argv , "13" , & arg1 , & arg2 , & arg3 , & arg4 ) ) {
634+ switch (argc ) {
640635 case 1 :
641636 if (rb_obj_is_kind_of (arg1 , cEC_GROUP )) {
642637 const EC_GROUP * arg1_group ;
@@ -718,9 +713,7 @@ ossl_ec_group_initialize_copy(VALUE self, VALUE other)
718713{
719714 EC_GROUP * group , * group_new ;
720715
721- TypedData_Get_Struct (self , EC_GROUP , & ossl_ec_group_type , group_new );
722- if (group_new )
723- ossl_raise (eEC_GROUP , "EC::Group already initialized" );
716+ ossl_want_uninitialized (self , & ossl_ec_group_type );
724717 GetECGroup (other , group );
725718
726719 group_new = EC_GROUP_dup (group );
@@ -1220,11 +1213,9 @@ static VALUE ossl_ec_point_initialize(int argc, VALUE *argv, VALUE self)
12201213 VALUE group_v , arg2 ;
12211214 const EC_GROUP * group ;
12221215
1223- TypedData_Get_Struct (self , EC_POINT , & ossl_ec_point_type , point );
1224- if (point )
1225- rb_raise (eEC_POINT , "EC_POINT already initialized" );
1226-
12271216 rb_scan_args (argc , argv , "11" , & group_v , & arg2 );
1217+ ossl_want_uninitialized (self , & ossl_ec_point_type );
1218+
12281219 if (rb_obj_is_kind_of (group_v , cEC_POINT )) {
12291220 if (argc != 1 )
12301221 rb_raise (rb_eArgError , "invalid second argument" );
@@ -1271,9 +1262,7 @@ ossl_ec_point_initialize_copy(VALUE self, VALUE other)
12711262 EC_GROUP * group ;
12721263 VALUE group_v ;
12731264
1274- TypedData_Get_Struct (self , EC_POINT , & ossl_ec_point_type , point_new );
1275- if (point_new )
1276- ossl_raise (eEC_POINT , "EC::Point already initialized" );
1265+ ossl_want_uninitialized (self , & ossl_ec_point_type );
12771266 GetECPoint (other , point );
12781267
12791268 group_v = rb_obj_dup (rb_attr_get (other , id_i_group ));
0 commit comments