diff options
author | Kazuki Yamaguchi <[email protected]> | 2020-05-17 22:14:03 +0900 |
---|---|---|
committer | Kazuki Yamaguchi <[email protected]> | 2021-07-18 17:44:49 +0900 |
commit | 38436d1f5cb03520a2a4acca81f013de1c20daa5 (patch) | |
tree | af5e66a7cd3b46324d081fda18bd8b68e5e1741a /ext/openssl/lib | |
parent | b8dcf9c8fd7c093bfac003d6293315e2c9b1e46f (diff) |
[ruby/openssl] pkey/dsa: use high level EVP interface to generate parameters and keys
Implement PKey::DSA.new(size) and PKey::DSA.generate using
OpenSSL::PKey.generate_parameters and .generate_key instead of the low
level DSA functions.
https://github.com/ruby/openssl/commit/1800a8d5eb
Diffstat (limited to 'ext/openssl/lib')
-rw-r--r-- | ext/openssl/lib/openssl/pkey.rb | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/ext/openssl/lib/openssl/pkey.rb b/ext/openssl/lib/openssl/pkey.rb index 3bef06e3b3..53ee52f98b 100644 --- a/ext/openssl/lib/openssl/pkey.rb +++ b/ext/openssl/lib/openssl/pkey.rb @@ -88,6 +88,36 @@ module OpenSSL::PKey class DSA include OpenSSL::Marshal + + class << self + # :call-seq: + # DSA.generate(size) -> dsa + # + # Creates a new DSA instance by generating a private/public key pair + # from scratch. + # + # See also OpenSSL::PKey.generate_parameters and + # OpenSSL::PKey.generate_key. + # + # +size+:: + # The desired key size in bits. + def generate(size, &blk) + dsaparams = OpenSSL::PKey.generate_parameters("DSA", { + "dsa_paramgen_bits" => size, + }, &blk) + OpenSSL::PKey.generate_key(dsaparams) + end + + # Handle DSA.new(size) form here; new(str) and new() forms + # are handled by #initialize + def new(*args, &blk) # :nodoc: + if args[0].is_a?(Integer) + generate(*args, &blk) + else + super + end + end + end end if defined?(EC) |