PATH:
opt
/
alt
/
ruby34
/
share
/
ruby
# -*- coding: us-ascii -*- # frozen_string_literal: true require 'random/formatter' # == Secure random number generator interface. # # This library is an interface to secure random number generators which are # suitable for generating session keys in HTTP cookies, etc. # # You can use this library in your application by requiring it: # # require 'securerandom' # # It supports the following secure random number generators: # # * openssl # * /dev/urandom # * Win32 # # SecureRandom is extended by the Random::Formatter module which # defines the following methods: # # * alphanumeric # * base64 # * choose # * gen_random # * hex # * rand # * random_bytes # * random_number # * urlsafe_base64 # * uuid # # These methods are usable as class methods of SecureRandom such as # +SecureRandom.hex+. # # If a secure random number generator is not available, # +NotImplementedError+ is raised. module SecureRandom # The version VERSION = "0.4.1" class << self # Returns a random binary string containing +size+ bytes. # # See Random.bytes def bytes(n) return gen_random(n) end # Compatibility methods for Ruby 3.2, we can remove this after dropping to support Ruby 3.2 def alphanumeric(n = nil, chars: ALPHANUMERIC) n = 16 if n.nil? choose(chars, n) end if RUBY_VERSION < '3.3' private # :stopdoc: # Implementation using OpenSSL def gen_random_openssl(n) return OpenSSL::Random.random_bytes(n) end # Implementation using system random device def gen_random_urandom(n) ret = Random.urandom(n) unless ret raise NotImplementedError, "No random device" end unless ret.length == n raise NotImplementedError, "Unexpected partial read from random device: only #{ret.length} for #{n} bytes" end ret end begin # Check if Random.urandom is available Random.urandom(1) alias gen_random gen_random_urandom rescue RuntimeError begin require 'openssl' rescue NoMethodError raise NotImplementedError, "No random device" else alias gen_random gen_random_openssl end end # :startdoc: # Generate random data bytes for Random::Formatter public :gen_random end end SecureRandom.extend(Random::Formatter)
[+]
yaml
[+]
strscan
[-] ostruct.rb
[edit]
[+]
ruby_vm
[+]
ripper
[-] coverage.rb
[edit]
[+]
set
[-] delegate.rb
[edit]
[-] open-uri.rb
[edit]
[+]
did_you_mean
[-] json.rb
[edit]
[-] openssl.rb
[edit]
[+]
json
[+]
prism
[-] objspace.rb
[edit]
[-] digest.rb
[edit]
[-] yaml.rb
[edit]
[-] bundled_gems.rb
[edit]
[+]
random
[-] forwardable.rb
[edit]
[+]
objspace
[-] weakref.rb
[edit]
[-] error_highlight.rb
[edit]
[-] benchmark.rb
[edit]
[-] uri.rb
[edit]
[-] English.rb
[edit]
[-] timeout.rb
[edit]
[+]
bigdecimal
[-] resolv.rb
[edit]
[+]
uri
[-] tsort.rb
[edit]
[-] find.rb
[edit]
[-] logger.rb
[edit]
[-] psych.rb
[edit]
[+]
psych
[+]
logger
[-] optparse.rb
[edit]
[+]
erb
[-] pp.rb
[edit]
[-] date.rb
[edit]
[-] ripper.rb
[edit]
[-] fiddle.rb
[edit]
[+]
io
[+]
unicode_normalize
[-] cgi.rb
[edit]
[-] pathname.rb
[edit]
[-] did_you_mean.rb
[edit]
[+]
vendor_ruby
[+]
forwardable
[+]
..
[-] prettyprint.rb
[edit]
[-] reline.rb
[edit]
[+]
reline
[-] securerandom.rb
[edit]
[+]
fiddle
[+]
error_highlight
[+]
digest
[-] optionparser.rb
[edit]
[+]
open3
[-] shellwords.rb
[edit]
[-] time.rb
[edit]
[+]
openssl
[+]
syntax_suggest
[-] fileutils.rb
[edit]
[-] socket.rb
[edit]
[+]
net
[-] monitor.rb
[edit]
[-] tempfile.rb
[edit]
[-] syntax_suggest.rb
[edit]
[-] un.rb
[edit]
[-] mkmf.rb
[edit]
[-] erb.rb
[edit]
[-] prism.rb
[edit]
[-] expect.rb
[edit]
[-] open3.rb
[edit]
[-] readline.rb
[edit]
[+]
cgi
[-] tmpdir.rb
[edit]
[-] ipaddr.rb
[edit]
[-] pstore.rb
[edit]
[-] singleton.rb
[edit]
[-] set.rb
[edit]
[+]
optparse