Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/smanonr..../opt/alt/ruby31/share/ruby
File: securerandom.rb
# -*- coding: us-ascii -*-
[0] Fix | Delete
# frozen_string_literal: true
[1] Fix | Delete
[2] Fix | Delete
require 'random/formatter'
[3] Fix | Delete
[4] Fix | Delete
# == Secure random number generator interface.
[5] Fix | Delete
#
[6] Fix | Delete
# This library is an interface to secure random number generators which are
[7] Fix | Delete
# suitable for generating session keys in HTTP cookies, etc.
[8] Fix | Delete
#
[9] Fix | Delete
# You can use this library in your application by requiring it:
[10] Fix | Delete
#
[11] Fix | Delete
# require 'securerandom'
[12] Fix | Delete
#
[13] Fix | Delete
# It supports the following secure random number generators:
[14] Fix | Delete
#
[15] Fix | Delete
# * openssl
[16] Fix | Delete
# * /dev/urandom
[17] Fix | Delete
# * Win32
[18] Fix | Delete
#
[19] Fix | Delete
# SecureRandom is extended by the Random::Formatter module which
[20] Fix | Delete
# defines the following methods:
[21] Fix | Delete
#
[22] Fix | Delete
# * alphanumeric
[23] Fix | Delete
# * base64
[24] Fix | Delete
# * choose
[25] Fix | Delete
# * gen_random
[26] Fix | Delete
# * hex
[27] Fix | Delete
# * rand
[28] Fix | Delete
# * random_bytes
[29] Fix | Delete
# * random_number
[30] Fix | Delete
# * urlsafe_base64
[31] Fix | Delete
# * uuid
[32] Fix | Delete
#
[33] Fix | Delete
# These methods are usable as class methods of SecureRandom such as
[34] Fix | Delete
# +SecureRandom.hex+.
[35] Fix | Delete
#
[36] Fix | Delete
# If a secure random number generator is not available,
[37] Fix | Delete
# +NotImplementedError+ is raised.
[38] Fix | Delete
[39] Fix | Delete
module SecureRandom
[40] Fix | Delete
class << self
[41] Fix | Delete
def bytes(n)
[42] Fix | Delete
return gen_random(n)
[43] Fix | Delete
end
[44] Fix | Delete
[45] Fix | Delete
private
[46] Fix | Delete
[47] Fix | Delete
def gen_random_openssl(n)
[48] Fix | Delete
@pid = 0 unless defined?(@pid)
[49] Fix | Delete
pid = $$
[50] Fix | Delete
unless @pid == pid
[51] Fix | Delete
now = Process.clock_gettime(Process::CLOCK_REALTIME, :nanosecond)
[52] Fix | Delete
OpenSSL::Random.random_add([now, @pid, pid].join(""), 0.0)
[53] Fix | Delete
seed = Random.urandom(16)
[54] Fix | Delete
if (seed)
[55] Fix | Delete
OpenSSL::Random.random_add(seed, 16)
[56] Fix | Delete
end
[57] Fix | Delete
@pid = pid
[58] Fix | Delete
end
[59] Fix | Delete
return OpenSSL::Random.random_bytes(n)
[60] Fix | Delete
end
[61] Fix | Delete
[62] Fix | Delete
def gen_random_urandom(n)
[63] Fix | Delete
ret = Random.urandom(n)
[64] Fix | Delete
unless ret
[65] Fix | Delete
raise NotImplementedError, "No random device"
[66] Fix | Delete
end
[67] Fix | Delete
unless ret.length == n
[68] Fix | Delete
raise NotImplementedError, "Unexpected partial read from random device: only #{ret.length} for #{n} bytes"
[69] Fix | Delete
end
[70] Fix | Delete
ret
[71] Fix | Delete
end
[72] Fix | Delete
[73] Fix | Delete
ret = Random.urandom(1)
[74] Fix | Delete
if ret.nil?
[75] Fix | Delete
begin
[76] Fix | Delete
require 'openssl'
[77] Fix | Delete
rescue NoMethodError
[78] Fix | Delete
raise NotImplementedError, "No random device"
[79] Fix | Delete
else
[80] Fix | Delete
alias gen_random gen_random_openssl
[81] Fix | Delete
end
[82] Fix | Delete
else
[83] Fix | Delete
alias gen_random gen_random_urandom
[84] Fix | Delete
end
[85] Fix | Delete
[86] Fix | Delete
public :gen_random
[87] Fix | Delete
end
[88] Fix | Delete
end
[89] Fix | Delete
[90] Fix | Delete
SecureRandom.extend(Random::Formatter)
[91] Fix | Delete
[92] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function