ruby-changes:70565
From: Yusuke <ko1@a...>
Date: Sat, 25 Dec 2021 03:32:52 +0900 (JST)
Subject: [ruby-changes:70565] 44bfe72892 (master): [ruby/openssl] Add tast cases to OpenSSL::BN using ractor
https://git.ruby-lang.org/ruby.git/commit/?id=44bfe72892 From 44bfe72892a5a07040d806c2aee89ee52955d86d Mon Sep 17 00:00:00 2001 From: Yusuke Nakamura <yusuke1994525@g...> Date: Tue, 21 Dec 2021 17:14:30 +0900 Subject: [ruby/openssl] Add tast cases to OpenSSL::BN using ractor OpenSSL::BN has been make ractor-safed in 9e7cf9e , but there was no test. And to use 'ractor' annotation, update test-unit to v3.4.6 or higher. https://github.com/ruby/openssl/commit/7541a66911 --- test/openssl/test_bn.rb | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/test/openssl/test_bn.rb b/test/openssl/test_bn.rb index 3f0622f94fd..346602dada2 100644 --- a/test/openssl/test_bn.rb +++ b/test/openssl/test_bn.rb @@ -334,6 +334,31 @@ class OpenSSL::TestBN < OpenSSL::TestCase https://github.com/ruby/ruby/blob/trunk/test/openssl/test_bn.rb#L334 e.set_flags(0) assert_equal(4, e.get_flags(OpenSSL::BN::CONSTTIME)) end + + if respond_to?(:ractor) + ractor + def test_ractor + assert_equal(@e1, Ractor.new { OpenSSL::BN.new("999") }.take) + assert_equal(@e3, Ractor.new { OpenSSL::BN.new("\a\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF", 2) }.take) + assert_equal("999", Ractor.new(@e1) { |e1| e1.to_s }.take) + assert_equal("07FFFFFFFFFFFFFFFFFFFFFFFFFF", Ractor.new(@e3) { |e3| e3.to_s(16) }.take) + assert_equal(2**107-1, Ractor.new(@e3) { _1.to_i }.take) + assert_equal([1000, -999], Ractor.new(@e2) { _1.coerce(1000) }.take) + assert_equal(false, Ractor.new { 1.to_bn.zero? }.take) + assert_equal(true, Ractor.new { 1.to_bn.one? }.take) + assert_equal(true, Ractor.new(@e2) { _1.negative? }.take) + assert_equal("-03E7", Ractor.new(@e2) { _1.to_s(16) }.take) + assert_equal(2**107-1, Ractor.new(@e3) { _1.to_i }.take) + assert_equal([1000, -999], Ractor.new(@e2) { _1.coerce(1000) }.take) + assert_equal(true, Ractor.new { 0.to_bn.zero? }.take) + assert_equal(true, Ractor.new { 1.to_bn.one? }.take ) + assert_equal(false,Ractor.new { 2.to_bn.odd? }.take) + assert_equal(true, Ractor.new(@e2) { _1.negative? }.take) + assert_include(128..255, Ractor.new { OpenSSL::BN.rand(8)}.take) + assert_include(0...2**32, Ractor.new { OpenSSL::BN.generate_prime(32) }.take) + assert_equal(0, Ractor.new { OpenSSL::BN.new(999).get_flags(OpenSSL::BN::CONSTTIME) }.take) + end + end end end -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/