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:
parent
9f5ab945b7
commit
c26cb08998
1 changed files with 8 additions and 6 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue