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

Defer to require prime for OpenSSL::TestBN

This commit is contained in:
Hiroshi SHIBATA 2021-05-26 19:51:33 +09:00
parent 9f192d42a6
commit b8dcad8d32
Notes: git 2021-05-27 14:42:36 +09:00

View file

@ -1,7 +1,6 @@
# coding: us-ascii
# frozen_string_literal: true
require_relative 'utils'
require "prime"
if defined?(OpenSSL)
@ -230,23 +229,29 @@ class OpenSSL::TestBN < OpenSSL::TestCase
}
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)
begin
require "prime"
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?)
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