Skip to content

Commit

Permalink
Merge pull request #59 from deivid-rodriguez/deivid-rodriguez/securer…
Browse files Browse the repository at this point in the history
…andom-is-always-there

Securerandom should be always available
  • Loading branch information
hsbt authored Dec 10, 2024
2 parents 77e399c + 324c355 commit 04f0438
Showing 1 changed file with 5 additions and 15 deletions.
20 changes: 5 additions & 15 deletions lib/resolv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
require 'socket'
require 'timeout'
require 'io/wait'

begin
require 'securerandom'
rescue LoadError
end
require 'securerandom'

# Resolv is a thread-aware DNS resolver library written in Ruby. Resolv can
# handle multiple DNS requests concurrently without blocking the entire Ruby
Expand Down Expand Up @@ -615,16 +611,10 @@ def extract_resources(msg, name, typeclass) # :nodoc:
}
end

if defined? SecureRandom
def self.random(arg) # :nodoc:
begin
SecureRandom.random_number(arg)
rescue NotImplementedError
rand(arg)
end
end
else
def self.random(arg) # :nodoc:
def self.random(arg) # :nodoc:
begin
SecureRandom.random_number(arg)
rescue NotImplementedError
rand(arg)
end
end
Expand Down

0 comments on commit 04f0438

Please sign in to comment.