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:
parent
e7d76fe2b0
commit
b9851c7e1b
Notes:
git
2022-02-16 16:32:47 +09:00
1 changed files with 5 additions and 4 deletions
|
@ -72,8 +72,11 @@ module SecureRandom
|
|||
ret
|
||||
end
|
||||
|
||||
ret = Random.urandom(1)
|
||||
if ret.nil?
|
||||
begin
|
||||
# Check if Random.urandom is available
|
||||
Random.urandom(1)
|
||||
alias gen_random gen_random_urandom
|
||||
rescue RuntimeError
|
||||
begin
|
||||
require 'openssl'
|
||||
rescue NoMethodError
|
||||
|
@ -81,8 +84,6 @@ module SecureRandom
|
|||
else
|
||||
alias gen_random gen_random_openssl
|
||||
end
|
||||
else
|
||||
alias gen_random gen_random_urandom
|
||||
end
|
||||
|
||||
public :gen_random
|
||||
|
|
Loading…
Reference in a new issue