aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorKazuki Yamaguchi <k@rhe.jp>2021-04-17 12:46:03 +0900
committerGitHub <noreply@github.com>2021-04-17 12:46:03 +0900
commitc3108404ab0e2eea3f83f580bb427dfacce559b8 (patch)
tree0f3b737b12bde3ee69ea7580d7381c8c34b2239b /lib
parent03cb3d5429ecd17736e2a063d4cbd7963799de28 (diff)
parent797e9f8e0865785df5a95c7344fa62a0a5c70e0b (diff)
downloadruby-openssl-c3108404ab0e2eea3f83f580bb427dfacce559b8.tar.gz
Merge pull request #436 from rhenium/ky/pkey-generic-evp-more
Use EVP API in more places
Diffstat (limited to 'lib')
-rw-r--r--lib/openssl/pkey.rb55
1 files changed, 55 insertions, 0 deletions
diff --git a/lib/openssl/pkey.rb b/lib/openssl/pkey.rb
index 53ee52f9..569559e1 100644
--- a/lib/openssl/pkey.rb
+++ b/lib/openssl/pkey.rb
@@ -11,6 +11,30 @@ module OpenSSL::PKey
include OpenSSL::Marshal
# :call-seq:
+ # dh.public_key -> dhnew
+ #
+ # Returns a new DH instance that carries just the \DH parameters.
+ #
+ # Contrary to the method name, the returned DH object contains only
+ # parameters and not the public key.
+ #
+ # This method is provided for backwards compatibility. In most cases, there
+ # is no need to call this method.
+ #
+ # For the purpose of re-generating the key pair while keeping the
+ # parameters, check OpenSSL::PKey.generate_key.
+ #
+ # Example:
+ # # OpenSSL::PKey::DH.generate by default generates a random key pair
+ # dh1 = OpenSSL::PKey::DH.generate(2048)
+ # p dh1.priv_key #=> #<OpenSSL::BN 1288347...>
+ # dhcopy = dh1.public_key
+ # p dhcopy.priv_key #=> nil
+ def public_key
+ DH.new(to_der)
+ end
+
+ # :call-seq:
# dh.compute_key(pub_bn) -> string
#
# Returns a String containing a shared secret computed from the other
@@ -89,6 +113,22 @@ module OpenSSL::PKey
class DSA
include OpenSSL::Marshal
+ # :call-seq:
+ # dsa.public_key -> dsanew
+ #
+ # Returns a new DSA instance that carries just the \DSA parameters and the
+ # public key.
+ #
+ # This method is provided for backwards compatibility. In most cases, there
+ # is no need to call this method.
+ #
+ # For the purpose of serializing the public key, to PEM or DER encoding of
+ # X.509 SubjectPublicKeyInfo format, check PKey#public_to_pem and
+ # PKey#public_to_der.
+ def public_key
+ OpenSSL::PKey.read(public_to_der)
+ end
+
class << self
# :call-seq:
# DSA.generate(size) -> dsa
@@ -159,6 +199,21 @@ module OpenSSL::PKey
class RSA
include OpenSSL::Marshal
+ # :call-seq:
+ # rsa.public_key -> rsanew
+ #
+ # Returns a new RSA instance that carries just the public key components.
+ #
+ # This method is provided for backwards compatibility. In most cases, there
+ # is no need to call this method.
+ #
+ # For the purpose of serializing the public key, to PEM or DER encoding of
+ # X.509 SubjectPublicKeyInfo format, check PKey#public_to_pem and
+ # PKey#public_to_der.
+ def public_key
+ OpenSSL::PKey.read(public_to_der)
+ end
+
class << self
# :call-seq:
# RSA.generate(size, exponent = 65537) -> RSA