static VALUE ossl_ec_point_initialize(int argc, VALUE *argv, VALUE self)
{
EC_POINT *point;
VALUE group_v, arg2;
const EC_GROUP *group;
TypedData_Get_Struct(self, EC_POINT, &ossl_ec_point_type, point);
if (point)
rb_raise(eEC_POINT, "EC_POINT already initialized");
rb_scan_args(argc, argv, "11", &group_v, &arg2);
if (rb_obj_is_kind_of(group_v, cEC_POINT)) {
if (argc != 1)
rb_raise(rb_eArgError, "invalid second argument");
return ossl_ec_point_initialize_copy(self, group_v);
}
GetECGroup(group_v, group);
if (argc == 1) {
point = EC_POINT_new(group);
if (!point)
ossl_raise(eEC_POINT, "EC_POINT_new");
}
else {
if (rb_obj_is_kind_of(arg2, cBN)) {
point = EC_POINT_bn2point(group, GetBNPtr(arg2), NULL, ossl_bn_ctx);
if (!point)
ossl_raise(eEC_POINT, "EC_POINT_bn2point");
}
else {
StringValue(arg2);
point = EC_POINT_new(group);
if (!point)
ossl_raise(eEC_POINT, "EC_POINT_new");
if (!EC_POINT_oct2point(group, point,
(unsigned char *)RSTRING_PTR(arg2),
RSTRING_LEN(arg2), ossl_bn_ctx)) {
EC_POINT_free(point);
ossl_raise(eEC_POINT, "EC_POINT_oct2point");
}
}
}
RTYPEDDATA_DATA(self) = point;
rb_ivar_set(self, id_i_group, group_v);
return self;
}