aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/secure_random.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport/lib/active_support/secure_random.rb')
-rw-r--r--activesupport/lib/active_support/secure_random.rb14
1 files changed, 8 insertions, 6 deletions
diff --git a/activesupport/lib/active_support/secure_random.rb b/activesupport/lib/active_support/secure_random.rb
index 97971e8830..cfbce4d754 100644
--- a/activesupport/lib/active_support/secure_random.rb
+++ b/activesupport/lib/active_support/secure_random.rb
@@ -1,16 +1,11 @@
begin
- require 'openssl'
-rescue LoadError
-end
-
-begin
require 'securerandom'
rescue LoadError
end
module ActiveSupport
if defined?(::SecureRandom)
- # Use Ruby 1.9's SecureRandom library whenever possible.
+ # Use Ruby's SecureRandom library if available.
SecureRandom = ::SecureRandom # :nodoc:
else
# = Secure random number generator interface.
@@ -64,6 +59,13 @@ module ActiveSupport
def self.random_bytes(n=nil)
n ||= 16
+ unless defined? OpenSSL
+ begin
+ require 'openssl'
+ rescue LoadError
+ end
+ end
+
if defined? OpenSSL::Random
return OpenSSL::Random.random_bytes(n)
end