ruby-changes:66316
From: Hiroshi <ko1@a...>
Date: Thu, 27 May 2021 14:42:36 +0900 (JST)
Subject: [ruby-changes:66316] b8dcad8d32 (master): Defer to require prime for OpenSSL::TestBN
https://git.ruby-lang.org/ruby.git/commit/?id=b8dcad8d32 From b8dcad8d32a5405cbbf29f6705c8975f1773170a Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA <hsbt@r...> Date: Wed, 26 May 2021 19:51:33 +0900 Subject: Defer to require prime for OpenSSL::TestBN --- test/openssl/test_bn.rb | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/test/openssl/test_bn.rb b/test/openssl/test_bn.rb index 547d334..6c26b5e 100644 --- a/test/openssl/test_bn.rb +++ b/test/openssl/test_bn.rb @@ -1,7 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/test/openssl/test_bn.rb#L1 # coding: us-ascii # frozen_string_literal: true require_relative 'utils' -require "prime" if defined?(OpenSSL) @@ -230,23 +229,29 @@ class OpenSSL::TestBN < OpenSSL::TestCase https://github.com/ruby/ruby/blob/trunk/test/openssl/test_bn.rb#L229 } end - def test_prime - p1 = OpenSSL::BN.generate_prime(32) - assert_include(0...2**32, p1) - assert_equal(true, Prime.prime?(p1.to_i)) - p2 = OpenSSL::BN.generate_prime(32, true) - assert_equal(true, Prime.prime?((p2.to_i - 1) / 2)) - p3 = OpenSSL::BN.generate_prime(32, false, 4) - assert_equal(1, p3 % 4) - p4 = OpenSSL::BN.generate_prime(32, false, 4, 3) - assert_equal(3, p4 % 4) - - assert_equal(true, p1.prime?) - assert_equal(true, p2.prime?) - assert_equal(true, p3.prime?) - assert_equal(true, p4.prime?) - assert_equal(true, @e3.prime?) - assert_equal(true, @e3.prime_fasttest?) + begin + require "prime" + + def test_prime + p1 = OpenSSL::BN.generate_prime(32) + assert_include(0...2**32, p1) + assert_equal(true, Prime.prime?(p1.to_i)) + p2 = OpenSSL::BN.generate_prime(32, true) + assert_equal(true, Prime.prime?((p2.to_i - 1) / 2)) + p3 = OpenSSL::BN.generate_prime(32, false, 4) + assert_equal(1, p3 % 4) + p4 = OpenSSL::BN.generate_prime(32, false, 4, 3) + assert_equal(3, p4 % 4) + + assert_equal(true, p1.prime?) + assert_equal(true, p2.prime?) + assert_equal(true, p3.prime?) + assert_equal(true, p4.prime?) + assert_equal(true, @e3.prime?) + assert_equal(true, @e3.prime_fasttest?) + end + rescue LoadError + # prime is the bundled gems at Ruby 3.1 end def test_num_bits_bytes -- cgit v1.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/