summaryrefslogtreecommitdiff
path: root/ext/openssl/ossl_bn.c
diff options
context:
space:
mode:
Diffstat (limited to 'ext/openssl/ossl_bn.c')
-rw-r--r--ext/openssl/ossl_bn.c22
1 files changed, 9 insertions, 13 deletions
diff --git a/ext/openssl/ossl_bn.c b/ext/openssl/ossl_bn.c
index c3a371a008..47a607e60f 100644
--- a/ext/openssl/ossl_bn.c
+++ b/ext/openssl/ossl_bn.c
@@ -107,11 +107,11 @@ ossl_bn_initialize(int argc, VALUE *argv, VALUE self)
VALUE str, bs;
int base = 10;
- GetBN(self, bn);
-
if (rb_scan_args(argc, argv, "11", &str, &bs) == 2) {
base = NUM2INT(bs);
}
+ StringValue(str);
+ GetBN(self, bn);
if (RTEST(rb_obj_is_kind_of(str, cBN))) {
BIGNUM *other;
@@ -121,8 +121,6 @@ ossl_bn_initialize(int argc, VALUE *argv, VALUE self)
}
return self;
}
- str = rb_String(str);
- StringValue(str);
switch (base) {
case 0:
@@ -159,11 +157,10 @@ ossl_bn_to_s(int argc, VALUE *argv, VALUE self)
int base = 10, len;
char *buf;
- GetBN(self, bn);
-
if (rb_scan_args(argc, argv, "01", &bs) == 1) {
base = NUM2INT(bs);
}
+ GetBN(self, bn);
switch (base) {
case 0:
len = BN_bn2mpi(bn, NULL);
@@ -380,11 +377,12 @@ BIGNUM_BIT(mask_bits);
static VALUE
ossl_bn_is_bit_set(VALUE self, VALUE bit)
{
+ int b;
BIGNUM *bn;
+ b = NUM2INT(bit);
GetBN(self, bn);
-
- if (BN_is_bit_set(bn, NUM2INT(bit))) {
+ if (BN_is_bit_set(bn, b)) {
return Qtrue;
}
return Qfalse;
@@ -397,8 +395,8 @@ ossl_bn_is_bit_set(VALUE self, VALUE bit)
BIGNUM *bn, *result; \
int b; \
VALUE obj; \
- GetBN(self, bn); \
b = NUM2INT(bits); \
+ GetBN(self, bn); \
if (!(result = BN_new())) { \
ossl_raise(eBNError, NULL); \
} \
@@ -550,11 +548,10 @@ ossl_bn_is_prime(int argc, VALUE *argv, VALUE self)
VALUE vchecks;
int checks = BN_prime_checks;
- GetBN(self, bn);
-
if (rb_scan_args(argc, argv, "01", &vchecks) == 0) {
checks = NUM2INT(vchecks);
}
+ GetBN(self, bn);
switch (BN_is_prime(bn, checks, NULL, ossl_bn_ctx, NULL)) {
case 1:
return Qtrue;
@@ -574,13 +571,12 @@ ossl_bn_is_prime_fasttest(int argc, VALUE *argv, VALUE self)
VALUE vchecks, vtrivdiv;
int checks = BN_prime_checks, do_trial_division = 1;
- GetBN(self, bn);
-
rb_scan_args(argc, argv, "02", &vchecks, &vtrivdiv);
if (!NIL_P(vchecks)) {
checks = NUM2INT(vchecks);
}
+ GetBN(self, bn);
/* handle true/false */
if (vtrivdiv == Qfalse) {
do_trial_division = 0;