summaryrefslogtreecommitdiff
path: root/lib/securerandom.rb
diff options
context:
space:
mode:
authorYusuke Endoh <mame@ruby-lang.org>2022-02-16 14:15:11 +0900
committerYusuke Endoh <mame@ruby-lang.org>2022-02-16 16:32:28 +0900
commitb9851c7e1b1cbc13b050831b0429e7a4097e11b7 (patch)
treedb2a9276fee170f75a147ce5a32e1a7cd7de4401 /lib/securerandom.rb
parente7d76fe2b0c504b96dc769a04cfb890a771b3675 (diff)
lib/securerandom.rb: Fix the check of availability of Random.urandom
Random.urandom raises a RuntimeError if it is unavailable. [Bug #13885]
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/5557
Diffstat (limited to 'lib/securerandom.rb')
-rw-r--r--lib/securerandom.rb9
1 files changed, 5 insertions, 4 deletions
diff --git a/lib/securerandom.rb b/lib/securerandom.rb
index 9cbf4ea789..07ae048634 100644
--- a/lib/securerandom.rb
+++ b/lib/securerandom.rb
@@ -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