summaryrefslogtreecommitdiff
path: root/ext/openssl/lib/openssl/pkey.rb
diff options
context:
space:
mode:
authorKazuki Yamaguchi <k@rhe.jp>2020-05-17 20:48:23 +0900
committerKazuki Yamaguchi <k@rhe.jp>2021-07-18 17:44:48 +0900
commitb8dcf9c8fd7c093bfac003d6293315e2c9b1e46f (patch)
treeefab56ac53c798bfcae6f2a1098a2aa9a782c16f /ext/openssl/lib/openssl/pkey.rb
parent098985a5e66e4dd6b01d246909b66d3d7e4024c0 (diff)
[ruby/openssl] pkey/rsa: use high level EVP interface to generate parameters and keys
Implement PKey::RSA.new(size, exponent) and PKey::RSA.generate using OpenSSL::PKey.generate_key instead of the low level RSA functions. https://github.com/ruby/openssl/commit/363fd10713
Diffstat (limited to 'ext/openssl/lib/openssl/pkey.rb')
-rw-r--r--ext/openssl/lib/openssl/pkey.rb30
1 files changed, 30 insertions, 0 deletions
diff --git a/ext/openssl/lib/openssl/pkey.rb b/ext/openssl/lib/openssl/pkey.rb
index 5a3d0ed1ef..3bef06e3b3 100644
--- a/ext/openssl/lib/openssl/pkey.rb
+++ b/ext/openssl/lib/openssl/pkey.rb
@@ -128,5 +128,35 @@ module OpenSSL::PKey
class RSA
include OpenSSL::Marshal
+
+ class << self
+ # :call-seq:
+ # RSA.generate(size, exponent = 65537) -> RSA
+ #
+ # Generates an \RSA keypair.
+ #
+ # See also OpenSSL::PKey.generate_key.
+ #
+ # +size+::
+ # The desired key size in bits.
+ # +exponent+::
+ # An odd Integer, normally 3, 17, or 65537.
+ def generate(size, exp = 0x10001, &blk)
+ OpenSSL::PKey.generate_key("RSA", {
+ "rsa_keygen_bits" => size,
+ "rsa_keygen_pubexp" => exp,
+ }, &blk)
+ end
+
+ # Handle RSA.new(size, exponent) 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
end