Module: Gem::SecureRandom
| Relationships & Source Files | |
| Super Chains via Extension / Inclusion / Inheritance | |
|
Class Chain:
self,
Random::Formatter
|
|
| Defined in: | lib/rubygems/vendor/securerandom/lib/securerandom.rb |
Constant Summary
-
VERSION =
# File 'lib/rubygems/vendor/securerandom/lib/securerandom.rb', line 48
The version
"0.4.1"
Class Method Summary
-
.alphanumeric(n = nil, chars: ALPHANUMERIC)
Compatibility methods for Ruby 3.2, we can remove this after dropping to support Ruby 3.2.
-
.bytes(n)
Returns a random binary string containing
sizebytes. -
.gen_random_openssl(n)
private
Internal use only
Implementation using OpenSSL.
-
.gen_random_urandom(n)
private
Internal use only
Implementation using system random device.
Class Method Details
.alphanumeric(n = nil, chars: ALPHANUMERIC)
Compatibility methods for Ruby 3.2, we can remove this after dropping to support Ruby 3.2
# File 'lib/rubygems/vendor/securerandom/lib/securerandom.rb', line 59
def alphanumeric(n = nil, chars: ALPHANUMERIC) n = 16 if n.nil? choose(chars, n) end
.bytes(n)
Returns a random binary string containing size bytes.
See Random.bytes
# File 'lib/rubygems/vendor/securerandom/lib/securerandom.rb', line 54
def bytes(n) return gen_random(n) end
.gen_random_openssl(n) (private)
This method is for internal use only.
Implementation using OpenSSL
# File 'lib/rubygems/vendor/securerandom/lib/securerandom.rb', line 69
def gen_random_openssl(n) return OpenSSL::Random.random_bytes(n) end
.gen_random_urandom(n) (private)
This method is for internal use only.
Implementation using system random device
# File 'lib/rubygems/vendor/securerandom/lib/securerandom.rb', line 74
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