aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorKazuki Yamaguchi <k@rhe.jp>2020-05-17 20:48:23 +0900
committerKazuki Yamaguchi <k@rhe.jp>2021-04-05 00:41:42 +0900
commit363fd107134fd2dbdf405fedec50dad13411057d (patch)
treed2653b9393c8751a2575a6081eb2501218b6fd15 /lib
parentc2e9b16f0b46371498232d68c01ac32d98a8ca0c (diff)
downloadruby-openssl-363fd107134fd2dbdf405fedec50dad13411057d.tar.gz
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.
Diffstat (limited to 'lib')
-rw-r--r--lib/openssl/pkey.rb30
1 files changed, 30 insertions, 0 deletions
diff --git a/lib/openssl/pkey.rb b/lib/openssl/pkey.rb
index 5a3d0ed1..3bef06e3 100644
--- a/lib/openssl/pkey.rb
+++ b/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