diff options
Diffstat (limited to 'test/openssl')
-rw-r--r-- | test/openssl/test_bn.rb | 35 |
1 files changed, 30 insertions, 5 deletions
diff --git a/test/openssl/test_bn.rb b/test/openssl/test_bn.rb index af1c72c8e9..27bbcdfeaf 100644 --- a/test/openssl/test_bn.rb +++ b/test/openssl/test_bn.rb @@ -3,13 +3,38 @@ require_relative 'utils' if defined?(OpenSSL) class OpenSSL::TestBN < Test::Unit::TestCase - def test_bn_to_bn - assert_equal(999.to_bn, OpenSSL::BN.new(999.to_bn)) + def test_new_str + e1 = OpenSSL::BN.new(999.to_s(16), 16) # OpenSSL::BN.new(str, 16) must be most stable + e2 = OpenSSL::BN.new((2**107-1).to_s(16), 16) + assert_equal(e1, OpenSSL::BN.new("999")) + assert_equal(e2, OpenSSL::BN.new((2**107-1).to_s)) + assert_equal(e1, OpenSSL::BN.new("999", 10)) + assert_equal(e2, OpenSSL::BN.new((2**107-1).to_s, 10)) + assert_equal(e1, OpenSSL::BN.new("\x03\xE7", 2)) + assert_equal(e2, OpenSSL::BN.new("\a\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF", 2)) + assert_equal(e1, OpenSSL::BN.new("\x00\x00\x00\x02\x03\xE7", 0)) + assert_equal(e2, OpenSSL::BN.new("\x00\x00\x00\x0E\a\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF", 0)) end - def test_integer_to_bn - assert_equal(999.to_bn, OpenSSL::BN.new(999.to_s(16), 16)) - assert_equal((2 ** 107 - 1).to_bn, OpenSSL::BN.new((2 ** 107 - 1).to_s(16), 16)) + def test_new_bn + e1 = OpenSSL::BN.new(999.to_s(16), 16) + e2 = OpenSSL::BN.new((2**107-1).to_s(16), 16) + assert_equal(e1, OpenSSL::BN.new(e1)) + assert_equal(e2, OpenSSL::BN.new(e2)) + end + + def test_new_integer + assert_equal(999.to_bn, OpenSSL::BN.new(999)) + assert_equal((2 ** 107 - 1).to_bn, OpenSSL::BN.new(2 ** 107 - 1)) + assert_equal(-999.to_bn, OpenSSL::BN.new(-999)) + assert_equal((-(2 ** 107 - 1)).to_bn, OpenSSL::BN.new(-(2 ** 107 - 1))) + end + + def test_to_bn + e1 = OpenSSL::BN.new(999.to_s(16), 16) + e2 = OpenSSL::BN.new((2**107-1).to_s(16), 16) + assert_equal(e1, 999.to_bn) + assert_equal(e2, (2**107-1).to_bn) end def test_prime_p |