diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2008-11-23 15:27:09 -0800 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2008-11-23 15:27:09 -0800 |
commit | c26cb089988c81b355b2d48bcbe343601fe214a0 (patch) | |
tree | b22eeda58136628c45d0d6fefac2c0482b81438c | |
parent | 9f5ab945b7118a317a12bd46c73d24575f31ce3f (diff) | |
download | rails-c26cb089988c81b355b2d48bcbe343601fe214a0.tar.gz rails-c26cb089988c81b355b2d48bcbe343601fe214a0.tar.bz2 rails-c26cb089988c81b355b2d48bcbe343601fe214a0.zip |
Lazy-require OpenSSL. Skip entirely if SecureRandom is available.
-rw-r--r-- | activesupport/lib/active_support/secure_random.rb | 14 |
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 |