[ruby/openssl] pkey: change PKey::{RSA,DSA,DH}#params to use nil for missing parameters
The returned Hash from these methods contain 0 in place of a missing parameter in the key, for example: pkey = OpenSSL::PKey.read(OpenSSL::PKey::RSA.new(2048).public_to_pem) pp pkey.params #=> # {"n"=>#<OpenSSL::BN https://github.com/ruby/openssl/commit/286934673421[...snip]>, # "e"=>#<OpenSSL::BN 65537>, # "d"=>#<OpenSSL::BN 0>, # "p"=>#<OpenSSL::BN 0>, # "q"=>#<OpenSSL::BN 0>, # "dmp1"=>#<OpenSSL::BN 0>, # "dmq1"=>#<OpenSSL::BN 0>, # "iqmp"=>#<OpenSSL::BN 0>} Let's use nil instead, which is more appropriate for indicating a missing value. https://github.com/ruby/openssl/commit/f247ec3dec
This commit is contained in:
parent
ec4592280f
commit
87316d58fa
@ -42,7 +42,7 @@ module OpenSSL::PKey
|
||||
# The hash has keys 'p', 'q', 'g', 'pub_key', and 'priv_key'.
|
||||
def params
|
||||
%w{p q g pub_key priv_key}.map { |name|
|
||||
[name, send(name) || 0.to_bn]
|
||||
[name, send(name)]
|
||||
}.to_h
|
||||
end
|
||||
|
||||
@ -174,7 +174,7 @@ module OpenSSL::PKey
|
||||
# The hash has keys 'p', 'q', 'g', 'pub_key', and 'priv_key'.
|
||||
def params
|
||||
%w{p q g pub_key priv_key}.map { |name|
|
||||
[name, send(name) || 0.to_bn]
|
||||
[name, send(name)]
|
||||
}.to_h
|
||||
end
|
||||
|
||||
@ -360,7 +360,7 @@ module OpenSSL::PKey
|
||||
# The hash has keys 'n', 'e', 'd', 'p', 'q', 'dmp1', 'dmq1', and 'iqmp'.
|
||||
def params
|
||||
%w{n e d p q dmp1 dmq1 iqmp}.map { |name|
|
||||
[name, send(name) || 0.to_bn]
|
||||
[name, send(name)]
|
||||
}.to_h
|
||||
end
|
||||
|
||||
|
@ -137,9 +137,9 @@ class OpenSSL::TestPKeyDH < OpenSSL::PKeyTestCase
|
||||
assert_kind_of(OpenSSL::BN, dh.g)
|
||||
assert_equal(dh.g, dh.params["g"])
|
||||
assert_nil(dh.pub_key)
|
||||
assert_equal(0, dh.params["pub_key"])
|
||||
assert_nil(dh.params["pub_key"])
|
||||
assert_nil(dh.priv_key)
|
||||
assert_equal(0, dh.params["priv_key"])
|
||||
assert_nil(dh.params["priv_key"])
|
||||
|
||||
dhkey = OpenSSL::PKey.generate_key(dh)
|
||||
assert_equal(dh.params["p"], dhkey.params["p"])
|
||||
|
@ -248,7 +248,7 @@ fWLOqqkzFeRrYMDzUpl36XktY6Yq8EJYlW9pCMmBVNy/dQ==
|
||||
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"])
|
||||
assert_nil(pubkey.params["priv_key"])
|
||||
end
|
||||
|
||||
def test_dup
|
||||
|
@ -595,7 +595,7 @@ class OpenSSL::TestPKeyRSA < OpenSSL::PKeyTestCase
|
||||
assert_equal(key.e, pubkey.e)
|
||||
[:d, :p, :q, :dmp1, :dmq1, :iqmp].each do |name|
|
||||
assert_nil(pubkey.send(name))
|
||||
assert_equal(0, pubkey.params[name.to_s])
|
||||
assert_nil(pubkey.params[name.to_s])
|
||||
end
|
||||
end
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user