New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Gem::Specification#to_ruby without OpenSSL #3059
Conversation
OpenSSL is an optional dependency of Ruby. Requiring openssl unconditionally means that Rubies that don't have the OpenSSL library won't be able to use RubyGems at all. In such a Ruby, an OpenSSL::PKey::RSA object can't exist, so we can just skip the check for those objects if there is no OpenSSL.
This require was added at #2937. Is Ruby without openssl supported by rubygems? Simple search for openssl at github (https://github.com/rubygems/rubygems/search?p=1&q=OpenSSL&unscoped_q=OpenSSL) shows different approaches how to handle OpenSSL presence. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
an idea to make the relationship between both code blocks more explicit
@@ -2414,7 +2414,10 @@ def test_files # :nodoc: | |||
# still have their default values are omitted. | |||
|
|||
def to_ruby | |||
require 'openssl' | |||
begin | |||
require 'openssl' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
require 'openssl' | |
require 'openssl' | |
has_openssl = true |
require 'openssl' | ||
begin | ||
require 'openssl' | ||
rescue LoadError |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rescue LoadError | |
rescue LoadError | |
has_openssl = false |
@@ -2454,7 +2457,9 @@ def to_ruby | |||
next if handled.include? attr_name | |||
current_value = self.send(attr_name) | |||
if current_value != default_value(attr_name) || self.class.required_attribute?(attr_name) | |||
result << " s.#{attr_name} = #{ruby_code current_value}" unless current_value.is_a?(OpenSSL::PKey::RSA) | |||
unless defined?(OpenSSL) && current_value.is_a?(OpenSSL::PKey::RSA) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unless defined?(OpenSSL) && current_value.is_a?(OpenSSL::PKey::RSA) | |
unless has_openssl && current_value.is_a?(OpenSSL::PKey::RSA) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this approach
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i prefer keeping consistent with the library by checking for the constant
@simi ruby is shipping with rubygems right? If ruby can have openssl disabled then rubygems should probably also support it at least for basic functionality. |
@simi ruby is shipping with rubygems right? If ruby can have openssl
disabled then rubygems should probably also support it at least for
basic functionality.
Correct. Because of this method, installing Ruby 2.7 at all without
OpenSSL is broken.
|
See https://bugs.ruby-lang.org/issues/16475 I think that rubygems does not have to seriously support an environment without openssl, but I want |
Just to give a use-case: a small ruby script that I want to distribute with a minimal installation of ruby. The script just uses the ruby stdlib and doesn't need network access so OpenSSL is not needed. |
Description:
OpenSSL is an optional dependency of Ruby. Requiring openssl
unconditionally means that Rubies that don't have the OpenSSL library
won't be able to use RubyGems at all.
In such a Ruby, an OpenSSL::PKey::RSA object can't exist, so we can
just skip the check for those objects if there is no OpenSSL.
Tasks:
I will abide by the code of conduct.