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

Lazy-require OpenSSL. Skip entirely if SecureRandom is available.

This commit is contained in:
Jeremy Kemper 2008-11-23 15:27:09 -08:00
parent 9f5ab945b7
commit c26cb08998

View file

@ -1,8 +1,3 @@
begin
require 'openssl'
rescue LoadError
end
begin
require 'securerandom'
rescue LoadError
@ -10,7 +5,7 @@ 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