ruby / openssl

Provides SSL, TLS and general purpose cryptography.
Other
241 stars 163 forks source link

pkey: change PKey::{RSA,DSA,DH}#params to use nil for missing parameters #774

Open rhenium opened 3 months ago

rhenium commented 3 months ago

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 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.


Also:

pkey: implement PKey::{RSA,DSA,DH}#params in Ruby

Move the definitions to lib/openssl/pkey.rb.

They don't have to be implemented in the native extension and can be simplified by using existing methods.