method
new
v2_5_5 -
Show latest stable
- Class:
OpenSSL::BN
new(p1, p2 = v2)public
static VALUE
ossl_bn_initialize(int argc, VALUE *argv, VALUE self)
{
BIGNUM *bn;
VALUE str, bs;
int base = 10;
if (rb_scan_args(argc, argv, "11", &str, &bs) == 2) {
base = NUM2INT(bs);
}
if (RB_INTEGER_TYPE_P(str)) {
GetBN(self, bn);
integer_to_bnptr(str, bn);
return self;
}
if (RTEST(rb_obj_is_kind_of(str, cBN))) {
BIGNUM *other;
GetBN(self, bn);
GetBN(str, other); /* Safe - we checked kind_of? above */
if (!BN_copy(bn, other)) {
ossl_raise(eBNError, NULL);
}
return self;
}
GetBN(self, bn);
switch (base) {
case 0:
if (!BN_mpi2bn((unsigned char *)StringValuePtr(str), RSTRING_LENINT(str), bn)) {
ossl_raise(eBNError, NULL);
}
break;
case 2:
if (!BN_bin2bn((unsigned char *)StringValuePtr(str), RSTRING_LENINT(str), bn)) {
ossl_raise(eBNError, NULL);
}
break;
case 10:
if (!BN_dec2bn(&bn, StringValueCStr(str))) {
ossl_raise(eBNError, NULL);
}
break;
case 16:
if (!BN_hex2bn(&bn, StringValueCStr(str))) {
ossl_raise(eBNError, NULL);
}
break;
default:
ossl_raise(rb_eArgError, "invalid radix %d", base);
}
return self;
} Related methods
- Instance methods
- %
- *
- **
- +
- +@
- -
- -@
- /
- <<
- <=>
- ==
- ===
- >>
- bit_set?
- clear_bit!
- cmp
- coerce
- copy
- eql?
- gcd
- hash
- initialize_copy
- lshift!
- mod_add
- mod_exp
- mod_inverse
- mod_mul
- mod_sqr
- mod_sub
- negative?
- num_bits
- num_bytes
- odd?
- one?
- pretty_print
- prime?
- prime_fasttest?
- rshift!
- set_bit!
- sqr
- to_bn
- to_i
- to_int
- to_s
- ucmp
- zero?
- Class methods
- generate_prime
- new
- pseudo_rand
- pseudo_rand_range
- rand
- rand_range