[ruby/openssl] pkey: add tests for PKey::{RSA,DSA,DH}#params

Add missing test cases to verify the current behavior. The next patch
will rewrite those methods.

c0e0669f9b
This commit is contained in:
Kazuki Yamaguchi 2024-06-14 14:50:21 +09:00
parent 72480389d1
commit 47fe59cd82
3 changed files with 60 additions and 0 deletions

View file

@ -230,6 +230,27 @@ fWLOqqkzFeRrYMDzUpl36XktY6Yq8EJYlW9pCMmBVNy/dQ==
assert_equal(nil, key.priv_key)
end
def test_params
key = Fixtures.pkey("dsa2048")
assert_kind_of(OpenSSL::BN, key.p)
assert_equal(key.p, key.params["p"])
assert_kind_of(OpenSSL::BN, key.q)
assert_equal(key.q, key.params["q"])
assert_kind_of(OpenSSL::BN, key.g)
assert_equal(key.g, key.params["g"])
assert_kind_of(OpenSSL::BN, key.pub_key)
assert_equal(key.pub_key, key.params["pub_key"])
assert_kind_of(OpenSSL::BN, key.priv_key)
assert_equal(key.priv_key, key.params["priv_key"])
pubkey = OpenSSL::PKey.read(key.public_to_der)
assert_equal(key.params["p"], pubkey.params["p"])
assert_equal(key.pub_key, pubkey.pub_key)
assert_equal(key.pub_key, pubkey.params["pub_key"])
assert_nil(pubkey.priv_key)
assert_equal(0, pubkey.params["priv_key"])
end
def test_dup
key = Fixtures.pkey("dsa1024")
key2 = key.dup