mirror of
https://github.com/ruby/ruby.git
synced 2025-08-26 06:25:31 +02:00
[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.
1800a8d5eb
This commit is contained in:
parent
b8dcf9c8fd
commit
38436d1f5c
3 changed files with 64 additions and 129 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue