Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

  • Loading branch information...
commit c26cb089988c81b355b2d48bcbe343601fe214a0 1 parent 9f5ab94
Jeremy Kemper jeremy authored
Showing with 8 additions and 6 deletions.
  1. +8 −6 activesupport/lib/active_support/secure_random.rb
14 activesupport/lib/active_support/secure_random.rb
View
@@ -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 SecureRandom
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
Please sign in to comment.
Something went wrong with that request. Please try again.