Skip to content

Commit

Permalink
Add tast cases to OpenSSL::BN using ractor
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
unasuke committed Dec 21, 2021
1 parent 4beb383 commit 7541a66
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ gemspec

gem "rake"
gem "rake-compiler"
gem "test-unit", "~> 3.0", ">= 3.4.3"
gem "test-unit", "~> 3.0", ">= 3.4.6"
gem "rdoc"
25 changes: 25 additions & 0 deletions test/openssl/test_bn.rb
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,31 @@ def test_get_flags_and_set_flags
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

0 comments on commit 7541a66

Please sign in to comment.