Skip to content

Conversation

@rhenium
Copy link
Member

@rhenium rhenium commented Aug 5, 2025

Remove the following subclasses of OpenSSL::PKey::PKeyError and make them aliases of it.

  • OpenSSL::PKey::DHError
  • OpenSSL::PKey::DSAError
  • OpenSSL::PKey::ECError
  • OpenSSL::PKey::RSAError

Historically, methods defined on OpenSSL::PKey and OpenSSL::PKey::PKey raise OpenSSL::PKey::PKeyError, while methods on the subclasses raise their respective exception classes. However, this distinction is not particularly useful since all those exception classes represent the same kind of errors from the underlying EVP_PKEY API.

I think this convention comes from the fact that OpenSSL::PKey::{DH, DSA,RSA} originally wrapped the corresponding OpenSSL structs DH, DSA, and RSA, before they were unified to wrap EVP_PKEY, way back in 2002.

OpenSSL::PKey::EC::Group::Error and OpenSSL::PKey::EC::Point::Error are out of scope of this change, as they are not subclasses of OpenSSL::PKey::PKeyError and do not represent errors from the EVP_PKEY API.

Remove the following subclasses of OpenSSL::PKey::PKeyError and make
them aliases of it.

 - OpenSSL::PKey::DHError
 - OpenSSL::PKey::DSAError
 - OpenSSL::PKey::ECError
 - OpenSSL::PKey::RSAError

Historically, methods defined on OpenSSL::PKey and OpenSSL::PKey::PKey
raise OpenSSL::PKey::PKeyError, while methods on the subclasses raise
their respective exception classes. However, this distinction is not
particularly useful since all those exception classes represent the
same kind of errors from the underlying EVP_PKEY API.

I think this convention comes from the fact that OpenSSL::PKey::{DH,
DSA,RSA} originally wrapped the corresponding OpenSSL structs DH, DSA,
and RSA, before they were unified to wrap EVP_PKEY, way back in 2002.

OpenSSL::PKey::EC::Group::Error and OpenSSL::PKey::EC::Point::Error
are out of scope of this change, as they are not subclasses of
OpenSSL::PKey::PKeyError and do not represent errors from the EVP_PKEY
API.
@rhenium rhenium force-pushed the ky/pkey-unify-errors branch from 2cba2db to e74ff3e Compare November 6, 2025 11:45
@rhenium rhenium merged commit 1f4a5a5 into ruby:master Nov 6, 2025
87 of 88 checks passed
enescakir added a commit to ubicloud/ubicloud that referenced this pull request Jan 6, 2026
First rubocop fails with the following error:

    lib/util.rb:29:3: W: Lint/ShadowedException: Do not shadow rescued Exceptions.
      rescue OpenSSL::PKey::ECError, OpenSSL::PKey::DSAError ...
      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

It's starting to complain about because errors are unified under
OpenSSL::PKey::PKeyError at ruby/openssl#929

So no need to rescue specific errors anymore, we can just rescue the
parent error.

Secondly, postgres_resource_nexus_spec test fails with the following
error:

  1) Prog::Postgres::PostgresResourceNexus#refresh_certificates rotates server certificate using root_cert_2 if root_cert_1 is close to expiration
     Failure/Error: expect { nx.refresh_certificates }.to hop("wait")

     ArgumentError:
       OpenSSL::PKey::EC.new cannot be called without arguments; pkeys are immutable with OpenSSL 3.0
     # ./prog/postgres/postgres_resource_nexus.rb:305:in 'OpenSSL::PKey::EC#initialize'
     # ./prog/postgres/postgres_resource_nexus.rb:305:in 'Class#new'
     # ./prog/postgres/postgres_resource_nexus.rb:305:in 'Prog::Postgres::PostgresResourceNexus#create_certificate'
     # ./prog/postgres/postgres_resource_nexus.rb:187:in 'Prog::Postgres::PostgresResourceNexus#refresh_certificates'
     # ./spec/prog/postgres/postgres_resource_nexus_spec.rb:324:in 'block (4 levels) in <top (required)>'
     # ./spec/spec_helper.rb:173:in 'block (3 levels) in <top (required)>'
     # ./spec/prog/postgres/postgres_resource_nexus_spec.rb:324:in 'block (3 levels) in <top (required)>'
     # ./spec/spec_helper.rb:62:in 'block (3 levels) in <top (required)>'
     # ./spec/spec_helper.rb:61:in 'block (2 levels) in <top (required)>'

It doesn't allow to pass nil to OpenSSL::PKey::EC.new anymore.
enescakir added a commit to ubicloud/ubicloud that referenced this pull request Jan 6, 2026
First rubocop fails with the following error:

    lib/util.rb:29:3: W: Lint/ShadowedException: Do not shadow rescued Exceptions.
      rescue OpenSSL::PKey::ECError, OpenSSL::PKey::DSAError ...
      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

It's starting to complain about because errors are unified under
OpenSSL::PKey::PKeyError at ruby/openssl#929

So no need to rescue specific errors anymore, we can just rescue the
parent error.

Secondly, postgres_resource_nexus_spec test fails with the following
error:

    1) Prog::Postgres::PostgresResourceNexus#refresh_certificates rotates server certificate using root_cert_2 if root_cert_1 is close to expiration
       Failure/Error: expect { nx.refresh_certificates }.to hop("wait")

       ArgumentError:
         OpenSSL::PKey::EC.new cannot be called without arguments; pkeys are immutable with OpenSSL 3.0
       # ./prog/postgres/postgres_resource_nexus.rb:305:in 'OpenSSL::PKey::EC#initialize'
       # ./prog/postgres/postgres_resource_nexus.rb:305:in 'Class#new'
       # ./prog/postgres/postgres_resource_nexus.rb:305:in 'Prog::Postgres::PostgresResourceNexus#create_certificate'
       # ./prog/postgres/postgres_resource_nexus.rb:187:in 'Prog::Postgres::PostgresResourceNexus#refresh_certificates'
       # ./spec/prog/postgres/postgres_resource_nexus_spec.rb:324:in 'block (4 levels) in <top (required)>'
       # ./spec/spec_helper.rb:173:in 'block (3 levels) in <top (required)>'
       # ./spec/prog/postgres/postgres_resource_nexus_spec.rb:324:in 'block (3 levels) in <top (required)>'
       # ./spec/spec_helper.rb:62:in 'block (3 levels) in <top (required)>'
       # ./spec/spec_helper.rb:61:in 'block (2 levels) in <top (required)>'

It doesn't allow to pass nil to OpenSSL::PKey::EC.new anymore.
enescakir added a commit to ubicloud/ubicloud that referenced this pull request Jan 7, 2026
First rubocop fails with the following error:

    lib/util.rb:29:3: W: Lint/ShadowedException: Do not shadow rescued Exceptions.
      rescue OpenSSL::PKey::ECError, OpenSSL::PKey::DSAError ...
      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

It's starting to complain about because errors are unified under
OpenSSL::PKey::PKeyError at ruby/openssl#929

So no need to rescue specific errors anymore, we can just rescue the
parent error.

Secondly, postgres_resource_nexus_spec test fails with the following
error:

    1) Prog::Postgres::PostgresResourceNexus#refresh_certificates rotates server certificate using root_cert_2 if root_cert_1 is close to expiration
       Failure/Error: expect { nx.refresh_certificates }.to hop("wait")

       ArgumentError:
         OpenSSL::PKey::EC.new cannot be called without arguments; pkeys are immutable with OpenSSL 3.0
       # ./prog/postgres/postgres_resource_nexus.rb:305:in 'OpenSSL::PKey::EC#initialize'
       # ./prog/postgres/postgres_resource_nexus.rb:305:in 'Class#new'
       # ./prog/postgres/postgres_resource_nexus.rb:305:in 'Prog::Postgres::PostgresResourceNexus#create_certificate'
       # ./prog/postgres/postgres_resource_nexus.rb:187:in 'Prog::Postgres::PostgresResourceNexus#refresh_certificates'
       # ./spec/prog/postgres/postgres_resource_nexus_spec.rb:324:in 'block (4 levels) in <top (required)>'
       # ./spec/spec_helper.rb:173:in 'block (3 levels) in <top (required)>'
       # ./spec/prog/postgres/postgres_resource_nexus_spec.rb:324:in 'block (3 levels) in <top (required)>'
       # ./spec/spec_helper.rb:62:in 'block (3 levels) in <top (required)>'
       # ./spec/spec_helper.rb:61:in 'block (2 levels) in <top (required)>'

It doesn't allow to pass nil to OpenSSL::PKey::EC.new anymore.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant