1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* ext/openssl/ossl_bn.c (ossl_bn_initialize): fix can't create from bn.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40090 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
naruse 2013-04-03 18:28:56 +00:00
parent 7181490def
commit 7b58445ebd
3 changed files with 12 additions and 2 deletions

View file

@ -1,3 +1,7 @@
Thu Apr 4 03:25:09 2013 NARUSE, Yui <naruse@ruby-lang.org>
* ext/openssl/ossl_bn.c (ossl_bn_initialize): fix can't create from bn.
Wed Apr 3 22:09:25 2013 Tanaka Akira <akr@fsij.org> Wed Apr 3 22:09:25 2013 Tanaka Akira <akr@fsij.org>
* ext/socket/extconf.rb: Test functions and libraries after headers. * ext/socket/extconf.rb: Test functions and libraries after headers.

View file

@ -119,11 +119,11 @@ ossl_bn_initialize(int argc, VALUE *argv, VALUE self)
if (rb_scan_args(argc, argv, "11", &str, &bs) == 2) { if (rb_scan_args(argc, argv, "11", &str, &bs) == 2) {
base = NUM2INT(bs); base = NUM2INT(bs);
} }
StringValue(str);
GetBN(self, bn);
if (RTEST(rb_obj_is_kind_of(str, cBN))) { if (RTEST(rb_obj_is_kind_of(str, cBN))) {
BIGNUM *other; BIGNUM *other;
GetBN(self, bn);
GetBN(str, other); /* Safe - we checked kind_of? above */ GetBN(str, other); /* Safe - we checked kind_of? above */
if (!BN_copy(bn, other)) { if (!BN_copy(bn, other)) {
ossl_raise(eBNError, NULL); ossl_raise(eBNError, NULL);
@ -131,6 +131,8 @@ ossl_bn_initialize(int argc, VALUE *argv, VALUE self)
return self; return self;
} }
StringValue(str);
GetBN(self, bn);
switch (base) { switch (base) {
case 0: case 0:
if (!BN_mpi2bn((unsigned char *)RSTRING_PTR(str), RSTRING_LENINT(str), bn)) { if (!BN_mpi2bn((unsigned char *)RSTRING_PTR(str), RSTRING_LENINT(str), bn)) {

View file

@ -3,6 +3,10 @@ require_relative 'utils'
if defined?(OpenSSL) if defined?(OpenSSL)
class OpenSSL::TestBN < Test::Unit::TestCase class OpenSSL::TestBN < Test::Unit::TestCase
def test_bn_to_bn
assert_equal(999.to_bn, OpenSSL::BN.new(999.to_bn))
end
def test_integer_to_bn def test_integer_to_bn
assert_equal(999.to_bn, OpenSSL::BN.new(999.to_s(16), 16)) assert_equal(999.to_bn, OpenSSL::BN.new(999.to_s(16), 16))
assert_equal((2 ** 107 - 1).to_bn, OpenSSL::BN.new((2 ** 107 - 1).to_s(16), 16)) assert_equal((2 ** 107 - 1).to_bn, OpenSSL::BN.new((2 ** 107 - 1).to_s(16), 16))