diff options
Diffstat (limited to 'test/test_pkey_dh.rb')
-rw-r--r-- | test/test_pkey_dh.rb | 41 |
1 files changed, 26 insertions, 15 deletions
diff --git a/test/test_pkey_dh.rb b/test/test_pkey_dh.rb index 78dedd1b..470c952e 100644 --- a/test/test_pkey_dh.rb +++ b/test/test_pkey_dh.rb @@ -3,7 +3,8 @@ require_relative 'utils' if defined?(OpenSSL::TestUtils) -class OpenSSL::TestPKeyDH < OpenSSL::TestCase +class OpenSSL::TestPKeyDH < OpenSSL::PKeyTestCase + DH1024 = OpenSSL::TestUtils::TEST_KEY_DH1024 NEW_KEYLEN = 256 @@ -35,20 +36,26 @@ class OpenSSL::TestPKeyDH < OpenSSL::TestCase end end - def test_to_der - dh = OpenSSL::TestUtils::TEST_KEY_DH1024 - der = dh.to_der - dh2 = OpenSSL::PKey::DH.new(der) - assert_equal_params(dh, dh2) - assert_no_key(dh2) - end - - def test_to_pem - dh = OpenSSL::TestUtils::TEST_KEY_DH1024 - pem = dh.to_pem - dh2 = OpenSSL::PKey::DH.new(pem) - assert_equal_params(dh, dh2) - assert_no_key(dh2) + def test_DHparams + asn1 = OpenSSL::ASN1::Sequence([ + OpenSSL::ASN1::Integer(DH1024.p), + OpenSSL::ASN1::Integer(DH1024.g) + ]) + key = OpenSSL::PKey::DH.new(asn1.to_der) + assert_same_dh dup_public(DH1024), key + + pem = <<~EOF + -----BEGIN DH PARAMETERS----- + MIGHAoGBAKnKQ8MNK6nYZzLrrcuTsLxuiJGXoOO5gT+tljOTbHBuiktdMTITzIY0 + pFxIvjG05D7HoBZQfrR0c92NGWPkAiCkhQKB8JCbPVzwNLDy6DZ0pmofDKrEsYHG + AQjjxMXhwULlmuR/K+WwlaZPiLIBYalLAZQ7ZbOPeVkJ8ePao0eLAgEC + -----END DH PARAMETERS----- + EOF + key = OpenSSL::PKey::DH.new(pem) + assert_same_dh dup_public(DH1024), key + + assert_equal asn1.to_der, DH1024.to_der + assert_equal pem, DH1024.export end def test_public_key @@ -104,6 +111,10 @@ class OpenSSL::TestPKeyDH < OpenSSL::TestCase assert(dh.pub_key) assert(dh.priv_key) end + + def assert_same_dh(expected, key) + check_component(expected, key, [:p, :q, :g, :pub_key, :priv_key]) + end end end |