diff options
author | rhe <rhe@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-12-10 08:12:02 +0000 |
---|---|---|
committer | rhe <rhe@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-12-10 08:12:02 +0000 |
commit | 9b18f4d60aa162b536c2cb895383b69687e58ced (patch) | |
tree | 05cb0b815f8e891636940286391ecaf105155eb1 /ext/openssl/ossl_bn.c | |
parent | fecc2e1700f82430c9b210fbe836d0e0954ede85 (diff) | |
download | ruby-9b18f4d60aa162b536c2cb895383b69687e58ced.tar.gz |
openssl: import v2.0.1
Import Ruby/OpenSSL 2.0.1. The full commit history since 2.0.0 (imported
at r56946) can be found at:
https://github.com/ruby/openssl/compare/v2.0.0...v2.0.1
This release contains only bug fixes. Note, the first two commits since
v2.0.0 are already imported at r56953 to make Travis and RubyCI green.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57041 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/openssl/ossl_bn.c')
-rw-r--r-- | ext/openssl/ossl_bn.c | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/ext/openssl/ossl_bn.c b/ext/openssl/ossl_bn.c index eaf62543a1..4e371cb201 100644 --- a/ext/openssl/ossl_bn.c +++ b/ext/openssl/ossl_bn.c @@ -120,30 +120,34 @@ integer_to_bnptr(VALUE obj, BIGNUM *orig) return bn; } -static BIGNUM * -try_convert_to_bnptr(VALUE obj) +static VALUE +try_convert_to_bn(VALUE obj) { - BIGNUM *bn = NULL; - VALUE newobj; + BIGNUM *bn; + VALUE newobj = Qnil; - if (rb_obj_is_kind_of(obj, cBN)) { - GetBN(obj, bn); - } - else if (RB_INTEGER_TYPE_P(obj)) { + if (rb_obj_is_kind_of(obj, cBN)) + return obj; + if (RB_INTEGER_TYPE_P(obj)) { newobj = NewBN(cBN); /* Handle potencial mem leaks */ bn = integer_to_bnptr(obj, NULL); SetBN(newobj, bn); } - return bn; + return newobj; } BIGNUM * -GetBNPtr(VALUE obj) +ossl_bn_value_ptr(volatile VALUE *ptr) { - BIGNUM *bn = try_convert_to_bnptr(obj); - if (!bn) + VALUE tmp; + BIGNUM *bn; + + tmp = try_convert_to_bn(*ptr); + if (NIL_P(tmp)) ossl_raise(rb_eTypeError, "Cannot convert into OpenSSL::BN"); + GetBN(tmp, bn); + *ptr = tmp; return bn; } @@ -893,10 +897,12 @@ ossl_bn_eq(VALUE self, VALUE other) BIGNUM *bn1, *bn2; GetBN(self, bn1); - /* BNPtr may raise, so we can't use here */ - bn2 = try_convert_to_bnptr(other); + other = try_convert_to_bn(other); + if (NIL_P(other)) + return Qfalse; + GetBN(other, bn2); - if (bn2 && !BN_cmp(bn1, bn2)) { + if (!BN_cmp(bn1, bn2)) { return Qtrue; } return Qfalse; |