Skip to content

Report unavailable OpenSSL through the documented error - #80

Open
OskarEichler wants to merge 1 commit into
ruby:masterfrom
OskarEichler:codex/handle-unavailable-openssl
Open

OskarEichler wants to merge 1 commit into
ruby:masterfrom
OskarEichler:codex/handle-unavailable-openssl

Conversation

@OskarEichler

Copy link
Copy Markdown

Summary

Rescue LoadError when the OpenSSL fallback cannot load, returning the documented NotImplementedError. Do not mask a NoMethodError raised inside loading as an unavailable random device.

Reproduction and verification

# Isolated fixture: Random.urandom(1) raises RuntimeError, and
# requiring openssl raises LoadError. Loading securerandom now
# raises NotImplementedError ('No random device'), preserving cause.

Three isolated module fixtures cover unavailable OpenSSL, an internal NoMethodError, and successful fallback byte generation. No global runtime or OS configuration was modified. Real OpenSSL length/encoding checks in the existing suite also pass.

  • Existing rbenv exec rake test: 3 tests / 68 assertions, zero failures/errors on the baseline, this isolated branch and the cumulative release-based consumer, Ruby 4.0.6/macOS. The existing disabled PID-recycling stress test was not enabled.
  • Combined candidate: 1,539 length/formatter checks, 3 fallback checks and 13 error/coercion/Ractor checks pass. Package build/extraction and existing rdoc -C checks pass (100% of its documentation inventory).
  • Paired benchmark, 10,000 16-byte calls per round: bytes median 0.010524s baseline / 0.010591s candidate; random_bytes 0.010651s / 0.010635s. Both allocate 10,000 objects. These small timings do not support a speedup claim.
  • No tests/specs added or modified under the consumer repository's explicit policy. External scratch reproductions were used.

Breaking changes and limitations

Intentional error-class correction only when the fallback fails to load: LoadError becomes the documented NotImplementedError; internal NoMethodError is no longer hidden. Successful backend selection and generated bytes are unchanged.

No production execution, statistical randomness claim, or cross-platform CI claim. Older Ruby/native fallback environments need upstream CI. The shared Random::Formatter implementation belongs to Ruby itself and is not changed here.

This branch has not been deployed

No deployments
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