Sync ruby/openssl

Pick https://github.com/ruby/openssl/pull/896
This commit is contained in:
Hiroshi SHIBATA 2025-06-06 11:11:38 +09:00
parent ca1c46d33c
commit 1dd8671c46
No known key found for this signature in database
GPG Key ID: F9CF13417264FAC2

View File

@ -345,29 +345,37 @@ class OpenSSL::TestBN < OpenSSL::TestCase
assert_equal(4, e.get_flags(OpenSSL::BN::CONSTTIME))
end
if respond_to?(:ractor)
if defined?(Ractor) && respond_to?(:ractor)
unless Ractor.method_defined?(:value) # Ruby 3.4 or earlier
using Module.new {
refine Ractor do
alias value take
end
}
end
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(@e1, Ractor.new { OpenSSL::BN.new("999") }.value)
assert_equal(@e3, Ractor.new { OpenSSL::BN.new("\a\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF", 2) }.value)
assert_equal("999", Ractor.new(@e1) { |e1| e1.to_s }.value)
assert_equal("07FFFFFFFFFFFFFFFFFFFFFFFFFF", Ractor.new(@e3) { |e3| e3.to_s(16) }.value)
assert_equal(2**107-1, Ractor.new(@e3) { _1.to_i }.value)
assert_equal([1000, -999], Ractor.new(@e2) { _1.coerce(1000) }.value)
assert_equal(false, Ractor.new { 1.to_bn.zero? }.value)
assert_equal(true, Ractor.new { 1.to_bn.one? }.value)
assert_equal(true, Ractor.new(@e2) { _1.negative? }.value)
assert_equal("-03E7", Ractor.new(@e2) { _1.to_s(16) }.value)
assert_equal(2**107-1, Ractor.new(@e3) { _1.to_i }.value)
assert_equal([1000, -999], Ractor.new(@e2) { _1.coerce(1000) }.value)
assert_equal(true, Ractor.new { 0.to_bn.zero? }.value)
assert_equal(true, Ractor.new { 1.to_bn.one? }.value )
assert_equal(false,Ractor.new { 2.to_bn.odd? }.value)
assert_equal(true, Ractor.new(@e2) { _1.negative? }.value)
assert_include(128..255, Ractor.new { OpenSSL::BN.rand(8)}.value)
assert_include(0...2**32, Ractor.new { OpenSSL::BN.generate_prime(32) }.value)
if !aws_lc? # AWS-LC does not support BN::CONSTTIME.
assert_equal(0, Ractor.new { OpenSSL::BN.new(999).get_flags(OpenSSL::BN::CONSTTIME) }.take)
assert_equal(0, Ractor.new { OpenSSL::BN.new(999).get_flags(OpenSSL::BN::CONSTTIME) }.value)
end
# test if shareable when frozen
assert Ractor.shareable?(@e1.freeze)