[前][次][番号順一覧][スレッド一覧]

ruby-changes:28038

From: naruse <ko1@a...>
Date: Thu, 4 Apr 2013 03:29:06 +0900 (JST)
Subject: [ruby-changes:28038] naruse:r40090 (trunk): * ext/openssl/ossl_bn.c (ossl_bn_initialize): fix can't create from bn.

naruse	2013-04-04 03:28:56 +0900 (Thu, 04 Apr 2013)

  New Revision: 40090

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=40090

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

  Modified files:
    trunk/ChangeLog
    trunk/ext/openssl/ossl_bn.c
    trunk/test/openssl/test_bn.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 40089)
+++ ChangeLog	(revision 40090)
@@ -1,3 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Thu Apr  4 03:25:09 2013  NARUSE, Yui  <naruse@r...>
+
+	* ext/openssl/ossl_bn.c (ossl_bn_initialize): fix can't create from bn.
+
 Wed Apr  3 22:09:25 2013  Tanaka Akira  <akr@f...>
 
 	* ext/socket/extconf.rb: Test functions and libraries after headers.
Index: ext/openssl/ossl_bn.c
===================================================================
--- ext/openssl/ossl_bn.c	(revision 40089)
+++ ext/openssl/ossl_bn.c	(revision 40090)
@@ -119,11 +119,11 @@ ossl_bn_initialize(int argc, VALUE *argv https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_bn.c#L119
     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;
 
+	GetBN(self, bn);
 	GetBN(str, other); /* Safe - we checked kind_of? above */
 	if (!BN_copy(bn, other)) {
 	    ossl_raise(eBNError, NULL);
@@ -131,6 +131,8 @@ ossl_bn_initialize(int argc, VALUE *argv https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_bn.c#L131
 	return self;
     }
 
+    StringValue(str);
+    GetBN(self, bn);
     switch (base) {
     case 0:
 	if (!BN_mpi2bn((unsigned char *)RSTRING_PTR(str), RSTRING_LENINT(str), bn)) {
Index: test/openssl/test_bn.rb
===================================================================
--- test/openssl/test_bn.rb	(revision 40089)
+++ test/openssl/test_bn.rb	(revision 40090)
@@ -3,6 +3,10 @@ require_relative 'utils' https://github.com/ruby/ruby/blob/trunk/test/openssl/test_bn.rb#L3
 if defined?(OpenSSL)
 
 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
     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))

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]