1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

lib/securerandom.rb: Fix the check of availability of Random.urandom

Random.urandom raises a RuntimeError if it is unavailable.
[Bug #13885]
This commit is contained in:
Yusuke Endoh 2022-02-16 14:15:11 +09:00
parent e7d76fe2b0
commit b9851c7e1b
Notes: git 2022-02-16 16:32:47 +09:00

View file

@ -72,8 +72,11 @@ module SecureRandom
ret ret
end end
ret = Random.urandom(1) begin
if ret.nil? # Check if Random.urandom is available
Random.urandom(1)
alias gen_random gen_random_urandom
rescue RuntimeError
begin begin
require 'openssl' require 'openssl'
rescue NoMethodError rescue NoMethodError
@ -81,8 +84,6 @@ module SecureRandom
else else
alias gen_random gen_random_openssl alias gen_random gen_random_openssl
end end
else
alias gen_random gen_random_urandom
end end
public :gen_random public :gen_random